4 ms·
Your variable my_string is a pointer to a constant string. char * my_string It must be a const char * my_string You can still assign a different string to th
by julian-klode 11y ago
Your variable my_string is a pointer to a constant string.
char * my_string
It must be a
const char * my_string
You can still assign a different string to that, as my_string is not const.
For my_string to be const, you'd have to use
char * const my_string
Now the location pointed to by my_string is writable but I cannot change the location.
To make it entirely unmodifiable, you'd use
const char * const my_string.
On the other hand, it might make more sense to use an array here.
const char my_string[] = "hello";