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,488
  • 25
  • 67
  • 86

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
  • 367,544
  • 15
  • 269
  • 518
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,412
  • 4
  • 32
  • 52