Search code examples
cconstantsdeclarationfunction-signature

What's the meaning of multiple const qualifiers?


Code:

const char* const* const* foo(int bar);

I've seen double consts before which prevent the modification of the pointer too. First time i've seen triple const in my life. Wondering what its use is.


Solution

  • In your example all but the top level of indirection all const qualified.

    const char            /* const qualified base level */
        *const            /* const qualified level 1 */
        *const            /* const qualified level 2 */
        *                 /* regular level 3 */
        foo(int bar);
    

    foo is a function that accepts an int argument and returns a regular pointer.
    The pointer it returns points to a const qualified pointer
    which, in turn, points to another const qualified pointer
    which points to const qualified char