Understanding C-strings & string literals in C++
问题 I have a few questions I would like to ask about string literals and C-strings. So if I have something like this: char cstr[] = "c-string"; As I understand it, the string literal is created in memory with a terminating null byte, say for example starting at address 0xA0 and ending at 0xA9, and from there the address is returned and/or casted to type char [ ] which then points to the address. It is then legal to perform this: for (int i = 0; i < (sizeof(array)/sizeof(char)); ++i) cstr[i] = 97