const char*

Could anybody please explain me the difference between the two following expressions:

char *const p1="John";
char const* p2="Mary";


what is constant in every case, in other words, what can be changed and what cannot be in each case.

Thanks
p2 is a pointer to a constant "Mary"
p2 can change to point to another constant string, but you can't change the value "May" thru p2.

p1 is a constant pointer to "John"
p1 can't change, but you can change "John" thru p1.
Thanks, but I'm still confused, the following was accepted by compiler

char const* p2="Mary";
p2="Margareth";


so, I changed the value of p2.

Could you please give me an example and show what could not be changed in this case?
Thanks
1
2
3
4
5
6
7
char const* p2 = "Mary";
*p2 = 'C'; // not allowed.
p2 = "Margareth";  // allowed

char * const p1 = "John";
*p1 = 'C'; // allowed
p1 = "Margarth"; // not allowed 
Thanks, I got it now; very clarifying example
Topic archived. No new replies allowed.