int x;x=1;
works the same as int x=1;
but
char str[20];
str="my name is bla bla";
does NOT work, whereas char str[20]="my name is bla bla";
works
Working on Code block with TDM-GCC-64 compiler
int x;x=1;
works the same as int x=1;
but
char str[20];
str="my name is bla bla";
does NOT work, whereas char str[20]="my name is bla bla";
works
Working on Code block with TDM-GCC-64 compiler
In C language strings are just arrays of characters. One can say that the core language itself is not even aware of the existence of strings - it is a library-level concept. (With the exception of string literals, perhaps, which are core language feature and which are strings.). In all respects strings are just arrays.
In C language naked arrays are generally not copyable, neither in assignment contexts nor in initialization contexts. Instead, arrays in C instantly decay to pointers with the exception of a few special contexts:
&
operatorsizeof
operator_Alignof
operatorchar[]
array with a string literal (in which case array copying actually takes place)Your example with initialization belongs to the above list, which is why it works. But your example with assignment is not an exception. In the latter case the general rule for array is applied: you can't assign arrays in C. In you want to copy a naked array, you have to use user-level or library-level code.