The character pointers in C is confusing me.
Suppose we have a char pointer, which points to the first character of string constant.
char *a="ABCD";
Then we cannot change the value of that character using the pointer a, as following statement results in a segmentation fault.
*a='X';
Now suppose we have a char pointer, which points to a character constant.
const char B='X';
char *ptr=&B;
Then we are allowed to change the value of that character using the statement
*ptr='Z';
My question is that is this a case of undefined behaviour proving C is not robust? Or is there some deeper logic involved?