There are two, unrelated, problems in that code. First, the const
is not in the right place.
char * const p = "john";
char const * p = "john";
const char * p = "john";
The latter two are pointers to unmodifiable strings. If you had done this, then the code would not have compiled.
The first option char * const
is not really a read-only variable. It means a pointer which points to modifiable data, and that the pointer cannot be changed such that it points to another string. But that's not relevant to your problem.
Your const
is not relevant here. You have attempted to modify a string that shouldn't be modified. Literal strings should never be modified, and this is the cause of your crash.