int main()
{
char *p = "hello world!";
p[0] = 'H';
printf("%s",p);
getch();
}
I am new to C, can u guys tell me why is this program giving a segmentation fault?
int main()
{
char *p = "hello world!";
p[0] = 'H';
printf("%s",p);
getch();
}
I am new to C, can u guys tell me why is this program giving a segmentation fault?
Because you try to set p[0]
to 'H'
. *p points to a string literal, which is stored in read-only memory.