#include<stdio.h>
int main(void)
{
char s='a',*j;
j=&s;
*j='b';
printf("s is %c",s);
}
Output: s is b.
From This program we get that we can change the values assigned to constant char by changing the value of the pointer.
But this doesnt happen with the following program.
#include<stdio.h>
int main(void)
{
char *p="Hello";
*p='z'; //By assuming that it should change 'H' as *p points to address of H//
printf("%c",*p);
}
Output: Segmentation Fault Core dumped
Shouldnt even in this case the value of the 0th char in the Hello change as we are manipulating its pointer,doesnt *p point to the value at address of H.Shouldnt the output expected here be "zello".