I'm reading appendix A of Accelerated C++. There the authors show an example of a declaration which looks like this:
const char * const * const * cp;
They say const char is the specifier and * const * const * cp is the declarator. I'm confused about the purpose of the extra const and *s. Is this a declaration of a const pointer to a const char?
It's the declaration of
const charThus you may change cp, but you may not change any of
*cp
**cp
***cp
As we can see from cdecl, cp is a pointer to const pointer to const pointer to const char.
You can see this by breaking it down right-to-left:
const char * const * const * cp;
cp is
a pointer
to const pointer
to const pointer
to const char
Also, the standard (§ 8) says that:
The specifiers indicate the type, storage class or other properties of the entities being declared. The declarators specify the names of these entities and (optionally) modify the type of the specifiers with operators such as * (pointer to) and () (function returning).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With