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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:34:59+00:00 2026-05-16T07:34:59+00:00

The const modifier in C++ before star means that using this pointer the value

  • 0

The const modifier in C++ before star means that using this pointer the value pointed at cannot be changed, while the pointer itself can be made to point something else. In the below

void justloadme(const int **ptr)
{
    *ptr = new int[5];
}

int main()
{
    int *ptr = NULL;
    justloadme(&ptr);
}

justloadme function should not be allowed to edit the integer values (if any) pointed by the passed param, while it can edit the int* value (since the const is not after the first star), but still why do I get a compiler error in both GCC and VC++?

GCC: error: invalid conversion from int** to const int**

VC++: error C2664: ‘justloadme’ : cannot convert parameter 1 from ‘int **’ to ‘const int **’. Conversion loses qualifiers

Why does it say that the conversion loses qualifiers? Isn’t it gaining the const qualifier? Moreover, isn’t it similar to strlen(const char*) where we pass a non-const char*

  • 1 1 Answer
  • 1 View
  • 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-16T07:35:00+00:00Added an answer on May 16, 2026 at 7:35 am

    As most times, the compiler is right and intuition wrong. The problem is that if that particular assignment was allowed you could break const-correctness in your program:

    const int constant = 10;
    int *modifier = 0;
    const int ** const_breaker = &modifier; // [*] this is equivalent to your code
    
    *const_breaker = & constant;   // no problem, const_breaker points to
                                   // pointer to a constant integer, but...
                                   // we are actually doing: modifer = &constant!!!
    *modifier = 5;                 // ouch!! we are modifying a constant!!!
    

    The line marked with [*] is the culprit for that violation, and is disallowed for that particular reason. The language allows adding const to the last level but not the first:

    int * const * correct = &modifier; // ok, this does not break correctness of the code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code: const string LabelToFind = goTo considered Harmful; using (var file = new
While striving for const-correctness, I often find myself writing code such as this class
I often use const for local variables that are not being modified, like this:
Const functions don't seem to care if you dereference a member-pointer into a non-const
I have a const int that is computed at compile time in my Managed
What is the purpose of the const in this? const Object myFunc(){ return myObject;
In C++, volatile is treated the same way const is: passing a pointer to
Every time I write trivial getters (get functions that just return the value of
I've got an API that looks like this: void WriteDefaultFileOutput(std::wostream &str, std::wstring target) {
This has some lengthy background before the actual question, however, it bears some explaining

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.