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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:21:07+00:00 2026-06-12T02:21:07+00:00

in this code: int* a; int* b; int c; int* d; a=new int(5); b=&(*a);

  • 0

in this code:

  int* a;
  int* b;
  int c;
  int* d;
  a=new int(5);
  b=&(*a);
  c=*a;
  d=&c;
  cout<<"*a = "<<*a<<endl;
  cout<<"a = "<<a<<endl;
  cout<<"b ="<<b<<endl;
  cout<<"d = "<<d<<endl;

I get:

*a = 5
 a = 0x83a2008
 b =0x83a2008
 d = 0xbfbfe540

why is d different from b? Aren’t they both &(*a) ? how can I get the d result with a single line?

Thanks a lot.

  • 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-06-12T02:21:08+00:00Added an answer on June 12, 2026 at 2:21 am

    a points to a dynamically allocated location, holding the value 5. When you do c = *a;, you’re copying the value 5 from that dynamically allocated location into c. You’re then taking the address of c and assigning it to d (and printing it out).

    When you end up with is something like this:

    enter image description here

    The solid lines indicate a pointer referring to a location. The dashed line indicates movement of data.

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

Sidebar

Related Questions

recently I have seen this code arrMove = new List<int[]>(4); m_pppiCaseMoveDiagLine = new int[64][][];
Does this code cause a memory leak: int main(){ int * a = new
For Andriod I have this code: public Tank(int color) { bounds = new RectF();
Having this code... var b = new ReadOnlyCollection<int>(new[] { 2, 4, 2, 2 });
i have this code: var list = new List<int>(); for(int i=0;i<10;i++) list.Add(i); for(int i=0;i<10;i++)
I have this code: hubSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int
The compiler complains about this code: HashMap<String,int> userName2ind = new HashMap<String,int>(); for (int i=0;
This is my code: uint16_t * ptemparr = new uint16_t[20]; for (int x=0;x<2;x++) {
I have code similar to this: public List<string> Expected = new List<string>(); public int
struct A { A(int) : i(new int(783)) { std::cout << a ctor << std::endl;

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.