3 ms·
That's not even correct. The type of string literals is "const char *".
by efaref 11y ago
That's not even correct. The type of string literals is "const char *".
- pbsd 11y agoTo be pedantic about it, string literals in C are of type `char[]`. In C++ they are of type `const char []`. In either case, altering the contents of the string literal is undefined behavior.
- plg 11y agoi 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";