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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:29:57+00:00 2026-05-24T05:29:57+00:00

Iv got to the stage in my c++ study concerning references. It states the

  • 0

Iv got to the stage in my c++ study concerning references. It states the following rule:

Once a reference is initialized to an object, it cannot be changed to refer to another object.

Iv wrote a short code (as asked to in an exercise) that is meant to prove this rule correct.

int y = 7;
int z = 8;

int&r = y;
r = z;

Can someone explain why this code compiles without any errors or warnings?

  • 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-24T05:29:59+00:00Added an answer on May 24, 2026 at 5:29 am

    r = z does not change what r “points to.” It assigns the value of z to the object pointed to by r.

    The following code does the same thing as your code, but using pointers instead of references:

    int y = 7;
    int z = 8;
    
    int* p = &y; // p points to y
    *p = z;      // assign value of z to the object pointed to by p (which is y)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a bare repo setup with the following branches: dev *master stage prod
I've got following array: private static Optreden[] optredens = { new Optreden(Editors, Main Stage,
Ok, so I've got the following code structure: var environment:AvEnvironment = new AvEnvironment(stage.stageWidth, stage.stageHeight);
I've got to the stage where I've written quite a bit of Erlang code
GOT error for the following query in MYSQL(version5.1) SELECT year,month,sum(fact_1),sum(fact_2),sum(fact_3),sum(fact_4) from( select year,month,fact_1,fact_2,0 as
I've got two models that look like this class Stage include DataMapper::Resource property :id,
I've got a view which looks like this: <p><%= stage.end_date.strftime(%A, %d %B %Y)%></p> Sometimes
Recently I have been looking into OpenGL, and I've got up to the stage
We've got a reasonable sized C++ application that's pretty old at this stage, so
I've got a clip that I'm drawing and adding to the stage, and when

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.