4
char const*const variablename = " ";

what does it mean?

is it same as pointer declaration?

Please anyone explain.

Thank you in advance!

Dhasneem
  • 4,037
  • 4
  • 33
  • 47
  • 1
    const always goes to the item immediately to its *left* unless it is the lead decl, in which case it is the first item to its right. I.e. `const char *` and `char const *` are the same. That said, this is a const pointer to const char data variable called `variablename` that is initialized (and always will be) to a read-only char string consisting of one space and one null-terminator. – WhozCraig Mar 19 '13 at 06:37
  • This question has been asked many times before; see also http://stackoverflow.com/questions/890535/what-is-the-difference-between-char-const-and-const-char http://stackoverflow.com/questions/4949254/const-char-const-versus-const-char http://stackoverflow.com/questions/6851436/difference-between-const-char-char-const-const-char-const-string-storage etc. – Adam Rosenfield Mar 19 '13 at 06:38

2 Answers2

6

It's a const pointer to a const C string. This means that neither the contents of the string, nor the pointer itself, can be changed.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
3

const protects his left side, unless there is nothing to his left and only then it protects his right side.

Applying this to your example, it's a const pointer to a const String.

Maroun
  • 94,125
  • 30
  • 188
  • 241