String is said to be a constant in C programming language.
So, when I give a statement like char *s = "Hello"
, I have learned that s
points to a memory location of H since "Hello" is stored in some static memory of the program and also "Hello"
is immutable.
Does it mean the variable s
is now a variable of type pointer to constant data such as const int a = 3;const int *i = &a;
. This seems so because I can't manipulate the data (when I do, it results in segmentation fault).
But, if it is so, shouldn't compiler be able to detect and say that I have assigned qualified data to unqualified variable.
Something like char *p
p is a pointer to unqualified character and when I say char *p="Hello"
p, the pointer to unqualified character can't point to a const character type?
What am I missing here?
If it is not the case as above, then how is an array of constant characters made immutable?