Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:12:46+00:00 2026-05-25T19:12:46+00:00

For reading complex pointer declarations there is the right-left rule . But this rule

  • 0

For reading complex pointer declarations there is the right-left rule.

But this rule does not mention how to read const modifiers.

For example in a simple pointer declaration, const can be applied in several ways:

char *buffer; // non-const pointer to non-const memory
const char *buffer; // non-const pointer to const memory
char const *buffer; // equivalent to previous declartion
char * const buffer = {0}; // const pointer to non-const memory
char * buffer const = {0}; // error
const char * const buffer = {0}; // const pointer to const memory

Now what about the use of const with a pointer of pointer declaration?

char **x; // no const;
const char **x;
char * const *x;
char * * const x;
const char * const * x;
const char * * const x;
const char * const * const x;

And what is an easy rule to read those declarations?
Which declarations make sense?

Is the Clockwise/Spiral Rule applicable?

Two real world examples

The method ASTUnit::LoadFromCommandLine uses const char ** to supply command line arguments (in the llvm clang source).

The argument vector parameter of getopt() is declared like this:

int getopt(int argc, char * const argv[], const char *optstring);

Where char * const argv[] is equivalent to char * const * argv in that context.

Since both functions use the same concept (a vector of pointers to strings to supply the arguments) and the declarations differ – the obvious questions are: Why do they differ? Makes one more sense than the other?

The intend should be: The const modifier should specify that the function does not manipulate strings of this vector and does not change the structure of the vector.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:12:47+00:00Added an answer on May 25, 2026 at 7:12 pm

    The const modifier is trivial: it modifies what precedes it, unless
    nothing precedes it. So:

    char const* buffer;  // const modifies char
    char* const buffer;  // const modifies *
    

    , etc. Generally, It’s best to avoid the forms where nothing precedes
    the const, but in practice, you’re going to see them, so you have to
    remember that when no type precedes the const, you have to logically
    move it behind the first type. So:

    const char** buffer;
    

    is in fact:

    char const** buffer;
    

    , i.e. pointer to pointer to const char.

    Finally, in a function declaration, a [] after reads as a * before.
    (Again, it’s probably better to avoid this misleading notation, but
    you’re going to see it, so you have to deal with it.) So:

    char * const argv[],  //  As function argument
    

    is:

    char *const * argv,
    

    a pointer to a const pointer to a char.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.