int main(void) {
char *temp = "ABCDE";
temp[2] = 'X';
printf("%s", temp);
return 0;
}
In gdb I could see that temp[2] = 'X' is causing the crash. But why? Could some answer please?
int main(void) {
char *temp = "ABCDE";
temp[2] = 'X';
printf("%s", temp);
return 0;
}
In gdb I could see that temp[2] = 'X' is causing the crash. But why? Could some answer please?
String literals are non-modifiable. It may be stored in read-only section of the memory and any attempt to modify it will lead to undefined behavior.
If you want to modify it, declare temp
as an array of char
s
char temp[] = "ABCDE";