Possible Duplicate:
Why do I get a segmentation fault when writing to a string?
I have the following program:
char *s = "abcdf";
char s1[50] = "abcdf";
s1[0] = 'Q'; // Line 1
s[0] = 'P'; // Line 2
Why Line 1 worked correctly and Line 2 caused the program to crash?
Line 2 points to the data section of your executable which is read-only, whereas in line 1, the program initializes
s1array with the given string. This is stored in stack, which you can modify.