A string literal is an array of char
that is not modifiable.
C99 6.4.5 p2:
A character string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in "xyz".
And then, in C99 6.4.5 p5:
In translation phase 7, a byte or code of value zero is appended to each multibyte
character sequence that results from a string literal or literals. The multibyte character
sequence is then used to initialize an array of static storage duration and length just
sufficient to contain the sequence. For character string literals, the array elements have
type char
, and are initialized with the individual bytes of the multibyte character
sequence;...
The draft C11 I have has similar wording. I believe it is worded with "have type char
" precisely to allow a string literal to be assigned to char *
. However, the standard does go on to say in C99 6.4.5 p6:
If the program attempts to modify such an array, the behavior is undefined.
So assignable, but not modifiable.
A string literal can be used as an initializer for an array of char
. From C99 6.7.8 p14:
An array of character type may be initialized by a character string literal, optionally
enclosed in braces. Successive characters of the character string literal (including the
terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.