Search code examples
c++pointersconstantsdeclaration

how to understand const and pointer in C++ expression below?


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 *?


Solution

  • 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.

    • The returned pointer, av, is non-const and can be changed.
    • The pointer av is pointing at is const and can not be changed.
    • The char that pointer is pointing at is const and can not be changed.