This piece of code throws seg fault.Please help me identify the reason for the same
#include<stdio.h>
int main() {
char* str;
str = "abcd";
str[0] = 'r';
printf("%c\n" , str[0]);
return 0;
}
thanks
Well explained in C FAQ 1.32. It's illegal to modify string literals.
6.4.5/6
It is unspecified whether these arrays are distinct provided their elements have the appropriate values. If the program attempts to modify such an array, the behavior is undefined.