char const * str
and const char * str
are the same, as const applies to the term on its left or, if there isn't a type on the left side, to the right one. That's why you get a double const error on const char const *
. Both are pointers on a constant char. You can change the value of the pointer, but not the dereferenced value:
const char * my_const_str;
my_const_str = "Hello world!"; // ok
my_const_str[0] = "h"; // error: my_const_str[0] is const!
char * const
on the other hand is a constant pointer. You cannot change the pointer, but you can change the value dereferenced by the pointer.
char * const my_const_ptr = malloc(10*sizeof(char));
my_const_str[0] = "h"; // ok
my_const_str = "hello world"; // error, you would change the value of my_const_str!