Why doesn't the compiler detect and produce errors when attempting to modify char * string literals?
问题 Assume the following two pieces of code: char *c = "hello world"; c[1] = 'y'; The one above doesn't work. char c[] = "hello world"; c[1] = 'y'; This one does. With regards to the first one, I understand that the string "hello world" might be stored in the read only memory section and hence can't be changed. The second one however creates a character array on the stack and hence can be modified. My question is this - why don't compilers detect the first type of error? Why isn't that part of