I was trying to understand segmentation fault for char * assignment during for the following program for at location *p = 'Z'
void main()
{
char *p ="abcdefg";
*p = 'Z';
}
When Googled, i did find many links to answers as follows 1. This is a string literal and once assigned cannot have its value changed 2. String literals cannot be assigned to *p 3. Take a malloc which can be changd... and so on...
But my worry was if string literals values can't be changed as it is constant, how come we don't segmentation fault when we change constant value of a integer. Can someone please help me understand this better?
-Prashanth