Reputation: 321
I am reading application code developed in the IBM RSARTE C++ version. Here is a piece of C++ code:
const char * const * av = RTMain::argStrings();
How to understand the left-hand side syntax when there are two const
and two *
?
Upvotes: 0
Views: 63
Reputation: 310950
Read this declaration
const char * const * av
from right to left. There is declared the pointer av
( * av
) that points to a constant pointer ( * const
) that in turn points to an object of the type const char
.
To simplify this declaration consider this code snippet.
const char *literal = "Hello World!";
const char * const * pointer_to_the pointer_literal = &literal;
So using the pointer pointer_to_the pointer_literal
you may not write for example
*pointer_to_the pointer_literal = "Bye";
and you may not write
**pointer_to_the pointer_literal = 'h';
Upvotes: 1
Reputation: 117298
const char * const * av = RTMain::argStrings();
is the same as
char const * const * av = RTMain::argStrings();
const
applies to what's left of const
.
So, av
is a non-const
pointer to a const*
to const char
.
av
, is non-const
and can be changed.av
is pointing at is const
and can not be changed.char
that pointer is pointing at is const
and can not be changed.Upvotes: 3