3 ms·
i didn't mean a const i meant a variable
by plg 11y ago
i didn't mean a const
i meant a variable
- julian-klode 11y agoYour 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";