Hi,
I am new to C programming and understanding the concept of pointers.
I have created a demo program of pointer for string operation as follow:
Code:
int main()
{
char *p = "CODER C++";
p = p + 2;
*p = 'X'; // segmentation fault
printf("%c",*p); // Prints D
printf("%s",p);
}
But this is giving segmentation fault.
if *p represents a character ( as it prints 'D' )value then I should be able to replace the value of *p with a "character" ..... but this is giving segmentation fault.
Can anybody explain the reason and solution to this.
Thanks