Time to confuse questions:
char s0[] = "Hello"; s0[0] = 'w';
This is absolutely true! Of course, this does not answer the original question, so we go: string literals are created in read-only memory. That is, their type is char const[n] , where n is the size of the string (including the terminating null character, ie n == 6 for the string literal "Hello" . But why, oh why this type can be used to initialize a char const* ? The answer is just backward compatibility, correspondingly compatible with the [old] C code: by the time const did this in the language, there are a lot of places already char* initialized with string literals.Any decent compiler should warn of this abuse, however .
source share