Interview Questions

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

C Interview Questions and Answers


(Continued from previous question...)

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

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.

(Continued on next question...)

Other Interview Questions