Const correctness
Const Correctness
Difference between char* and const char*?
char*
is a mutable pointer to a mutable character/string.
const char*
/ char const *
is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from const char *
to char*
is deprecated.
char * const
is an immutable pointer (it cannot point to any other location) but the contents of location at which it points are mutable.
const char* const
/ char const * const
is an immutable pointer to an immutable character/string.
Quiz (PDF)