In C, why can’t I assign a string to a char array after it’s declared?

Arrays are second-class citizens in C, they do not support assignment.

char x[] = "This is initialization, not assignment, thus ok.";

This does not work:

x = "Compilation-error here, tried to assign to an array.";

Use library-functions or manually copy every element for itself:

#include <string.h>
strcpy(x, "The library-solution to string-assignment.");

Leave a Comment