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 6103743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:45:49+00:00 2026-05-23T13:45:49+00:00

I am having trouble finding an intuitive pattern for the way const is used

  • 0

I am having trouble finding an intuitive pattern for the way const is used in declarations in the C and C++ languages. Here are some examples:

const int a;    //Const integer
int const a;    //Const integer
const int * a;  //Pointer to constant integer
int * const a;  //Const pointer to an integer
int const * a const;    //Const pointer to a const integer

In lines 1 and 2, it seems const can come before or after int, which is what it modifies.

  1. So how, in line 4, does the compiler decide that const is modifying * (pointer) rather than int?
  2. What is the rule that the compiler follows for deciding which thing the const applies to?
  3. Does it follow the same rule for *?
  • 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-23T13:45:49+00:00Added an answer on May 23, 2026 at 1:45 pm

    The compiler generally reads the type from right-to-left, so:

    T const& const
    

    Would be read as:

     const (a constant)
     & (to a reference)
     const (to a constant)
     T (of type T)
    

    So, basically the keyword “const” modifies everything that precedes it. However, there is an exception in the case where “const” comes first, in which case it modifies the item directly to the right of it:

    const T& const
    

    The above is read as:

    const (a constant)
    & (to a reference)
    const T (to a constant of type T)
    

    And the above is equivalent to T const& const.

    While this is how the compiler does it, I really just recommend memorizing the cases “T”, “const T”, “const T&”, “const T*”, “const T& const”, “const T* const”, “T& const”, and “T* const”. You will rarely encounter any other variation of “const”, and when you do, it’s probably a good idea to use a typedef.

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

Sidebar

Related Questions

Having trouble finding a solution for my situation here. Sorry if this has been
I'm having trouble finding my way around Zend Framework documentation. I'm currently using the
I'm having trouble finding a way to write a query that will return all
I'm having trouble finding an open-source IDE with support for Git. Are there any
I'm looking to try out JRuby and JRuby on Rails. I'm having trouble finding
I'm using the python optparse module in my program, and I'm having trouble finding
My app will be full screen, but I am having trouble finding the document
I'm having the trouble finding the wording, but is it possible to provide a
I am having a lot of trouble finding good information on how to call
I am having trouble finding a class or API in Android documentation that would

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.