-
It’s
const char* p = "C language";
, notchar* const
. They have different meanings:const char* p
means that the chars to whichp
points to, cannot be modified; whilechar* const p
means that the pointerp
itself cannot be modified. -
*p = "Change";
is not the correct way to change string’s content. Even when the string is not read-only. One way to modify a string’s content is to use:strcpy(p, "Change")
-
You cannot modify string literals because they are read-only by definition. However, you can declare “char arrays”, and they can be modified:
char s[] = "C language"; printf("%s\n", s); strcpy(s, "Change"); printf("%s\n", s);
solved Why can’t i change the content of a constant char pointer in C?