2

Possible Duplicate:
about “int const *p” and “const int *p ”

Difference between

const  char *p

and

char * const p?

is that fist one means cannot change char. Later one means cannot change the pointer. Am I right? Thank you!

Community
  • 1
  • 1
Josh Morrison
  • 7,288
  • 24
  • 65
  • 85

2 Answers2

10
const char *p

means the characters cannot be changed. *p = '\0' is illegal. Var p is a pointer to a const char.

char * const p

means the pointer cannot be changed. p = 0 is illegal. Constant p is a pointer to a char.

const char * const p

means neither can be changed. Constant p is a pointer to a const char.

Update: Added third declaration.

ikegami
  • 343,984
  • 15
  • 249
  • 495
3

In the first you can't edit the pointee and in the second you can't edit the pointer. Have a look at this perhaps.

Morten Kristensen
  • 7,267
  • 4
  • 30
  • 51