Why does modifying a pre-initialized string literal cause a segmentation fault? For example:
char *str = "Hello world";
str[0] = 'h';
When you initialize str
to that string value, doesn't the compiler automatically allocate memory for that string constant, assign its starting location to str
and free it upon program exit?