If you cant modify string literals, why arent they defined as being arrays of const characters?

Q

If you cant modify string literals, why arent they defined as being arrays of const characters?

✍: Guest

A

One reason is that so very much code contains lines like
char *p = "Hello, world!";
which are not necessarily incorrect. These lines would suffer the diagnostic messages, but it's really any later attempt to modify what p points to which would be problems.

2016-01-06, 597👍, 0💬