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

  • SEARCH
  • Home
  • 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
  • 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-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

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't have Crystal Reports handy, but off the top… May 16, 2026 at 5:07 pm
  • Editorial Team
    Editorial Team added an answer Try calling DRAWNOW. set(handles.lblStatus,'String','Processing...') drawnow %function that takes a long… May 16, 2026 at 5:07 pm
  • Editorial Team
    Editorial Team added an answer Templates are faster, in my test cases (of which results… May 16, 2026 at 5:07 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This has some lengthy background before the actual question, however, it bears some explaining
There are many questions discussing the details of C and C++ dealing with pointer-to-const
long make_checksum(const char* str) { long chk=0; long rot=0; while(*str) { rot<<=9; rot|=(rot>>23); rot^=*(char*)str++;
I have const char* FilePathName which looks like this: C:\ImportantFile.hex And an int id
I found that handy opencv library and tried to program a simple imagemodifier with
Why does the following code in C work? const char* str = NULL; str
I have a std::map that I use to map values (field ID's) to a
Is there any other way to change the QTextLayout of a QTextBlock that is
I've read that static variables are used inside function when one doesn't want the
I've got the following function prototype: bool key_pressed(enum key key) const; I documented it

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.