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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:50:08+00:00 2026-05-18T22:50:08+00:00

Im having trouble understanding the meaning of const int* const &alias_for_ptr = ptr; with

  • 0

Im having trouble understanding the meaning of const int* const &alias_for_ptr = ptr;
with regards to the following:

#include <iostream>
using namespace std;

int main() {

    int a = 10;

    int* ptr = &a;
    const int* const &alias_for_ptr = ptr;

    ptr = NULL; //or ptr = 0;

    if (ptr == alias_for_ptr)
        //This should execute but doesn't
        cout << "ptr == alias_for_ptr" << endl;
    else
        //This should NOT execute but DOES
        cout << "ptr != alias_for_ptr" << endl;
    return 0;

}

Why is it that ptr == alias_for_ptr returns false, (in fact alias_for_ptr retains its old value of &a)? I was under the impression that alias_for_ptr will always have the same value as ptr (though the use of the & symbol) and that const int* const X = Y only ensures that I cannot change both the value of X and the value pointed by X through that identifier X.

Also if I remove the second const then the script will not compile, which confuses me futher. Note that the compile error is: invalid initialization of reference of type ‘const int*&’ from expression of type ‘int*’.

  • 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-18T22:50:09+00:00Added an answer on May 18, 2026 at 10:50 pm

    Which compiler are you using? I’ve compiled under MSVC++ 2010, and it works as you expect.

    I think what’s happening is a temporary is being assigned to a const-reference, since the type of “ptr” is converted from “int*” to a “const int*”. What happens if you remove the first const?

    EDIT: Read here for more on references: Reference initialization in C++.

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

Sidebar

Related Questions

I'm having trouble understanding following code: if (IsPostBack) { int CheckBoxIndex; ArrayList CheckBoxArray; bool
I'm having trouble understanding where I went wrong with my code: #include <iostream> #include
I am having trouble understanding the following code block. int count = 0; for
I am having trouble understanding the meaning and more importantly the concept of an
from here Im having trouble understanding they say that ado.net does not include a
I'm having trouble understanding the result of the following statements: >>> from array import
Im having trouble understanding why the following code displays The First Key = (null)
I'm having trouble understanding why the Foo move constructor tries to invoke ~ptr in
I'm having trouble understanding how to get the following working in interface builder. I've
I'm having trouble understanding how QGraphicsItemAnimation's setScaleAt function works. Here's the code I'm using:

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.