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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:37:14+00:00 2026-05-31T00:37:14+00:00

We are studying for our CS midterm on Tuesday. Our professor put some study

  • 0

We are studying for our CS midterm on Tuesday.

Our professor put some study material online, including the following:

“Further, you should be able to draw a memory diagram given some code, such as:”

void foo( int &x )
{
 x = 1000;
}

void bar( int *x )
{
 *x = 1000;
}

void foobar( int x )
{
 x = 1000;
}

int main()
{
   int x = 1234;
   int &y = x;

   int *z = &x;

   int  array_1[5];
   int *array_2[5];

   array_1[0] = 10;
   array_2[0] = (int*)10;
   array_2[1] = &y;

   array_2[2] = &x;

   foo( x );
   foo( y );
   foo( *z );

   bar( &x );
   bar( &y );
   bar( z );

   foobar( x );
   foobar( y );
   foobar( *z );

   return 0;
}

We are trying to go through it one step at a time, to see what is allocated on the stack, what is allocated on the heap, and what is the value of each thing.

What we don’t understand is:
&y holds the address of x, but &y = &x… so what is the address of y? Like, doesn’t the stack need to hold y???

  • 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-31T00:37:15+00:00Added an answer on May 31, 2026 at 12:37 am

    Long story short – there is no spoon y. So nothing will be allocated on stack for y. This is because y in your case is a reference.

    Reference is just an alias and has no address. In other words – it is the same thing as x, but named differently. That’s how you should think of references as a C++ programmer. In fact, compiler might use an address of the object in order to implement a reference (i.e. when you pass by reference). And even in that case it might be only stored in a register, thus have no memory address. But these are implementation details you are not supposed to know about 🙂 I recommend you check out this C++ References FAQ.

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

Sidebar

Related Questions

Studying some code from a codeigniter tut, the following preg_match pattern has me baffled:
I'm studying ICT. One of my courses is C# and another is Physics. Our
While studying Java tutorials, Reflection and Late Binding have confused me. In some tutorials,
While studying the Collection API, we find that some methods ( add , remove
I'm looking to put together a form on our website that would feature a
Im studying some ruby code and I see this varx variable being used with
I'm studying Java Concurrency in Practice and there it is explained why the following
studying some sample code from an iOS programming course (cs193p fall2010) i came across
I am new to studying jquery.ajax. Through some tutorials, I tried some code by
while studying some security things, there was a question that one can guess the

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.