Consider the following code.
int main(void) {
char * test = "abcdefghijklmnopqrstuvwxyz";
test[5] = 'x';
printf("%s
", test);
return EXIT_SUCCESS;
}
In my opinion, this should print abcdexghij. However, it just terminates without printing anything.
int main(void) {
char * test = "abcdefghijklmnopqrstuvwxyz";
printf("%s
", test);
return EXIT_SUCCESS;
}
This however, works just fine, so did I misunderstand the concept of manipulating C strings or something? In case it is important, I'm running Mac OS X 10.6 and it is a 32-bit binary I'm compiling.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…