...
At compile time, string literals are used to create an array of static storage duration of sufficient length to contain the character sequence and a terminating null character. It is unspecified whether these arrays of string literals are distinct from each other. The behavior is undefined if a program attempts to modify any string literals. Modifying a string literal frequently results in an access violation because string literals are typically stored in read-only memory. See also undefined behavior 33 of Annex J of the C Standard.
String literals are usually referred to via a pointer to, or array of characters. Ideally they should be assigned only to pointers to (or arrays of) const char
.
...
As an array initializer, a string literal specifies the initial values of characters in an array as well as the size of the array. (See STR36 STR11-C. Do not specify the bound of a character array initialized with a string literal.) This code creates a copy of the string literal in the space allocated to the character array a
. The string stored in a
can be safely modified.
...
...
[ISO/IEC 9899:2011] | 6.4.5, "String literals" Annex J, subclause J.2, "Undefined Behavior" |
[Plum 1991] | Topic 1.26, "Strings—String Literals" |
[Summit 1995] | comp.lang.c FAQ list, Question 1.32 |
...