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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:55:55+00:00 2026-06-08T02:55:55+00:00

In the following code, based on reading cplusplus.com , I’m trying to test my

  • 0

In the following code, based on reading cplusplus.com, I’m trying to test my basic understanding on pointers.

#include <iostream>
using namespace std;

int main() {
    int foo, *bar, fubar;
    foo = 81;
    bar = &foo;
    fubar = *bar;
    cout << "the value of foo is " << foo << endl;
    cout << "the value of &foo is " << &foo << endl;
    cout << "the value of bar is " << bar << endl;
    cout << "the value of *bar is " << *bar << endl;
    cout << "the value of fubar is " << fubar << endl;
    cin.get();
}

That leads to the output:

the value of foo is 81
the value of &foo is xx
the value of bar is xx
the value of *bar is 81
the value of fubar is 81

Where xx is some long number that changes at each runtime.
When I add the following:

    cout << "the address of foo is " << &foo << endl;
    cout << "the address of fubar is " << &fubar << endl;

It leads to:

the address of foo is xx
the address of fubar is xy

Where xy is different to xx on runtime.

  • Question 1: At the declarations, does the declaration *bar make it a ‘pointer’ at that moment in time, until it is used i.e. fubar = *bar at which point is it a dereferenced variable? Or is it that a pointer is always a variable and that’s just me getting all nooby and tied down in (probably incorrect) semantics?

  • Question 2: xx is a long number that changes each runtime so am I right that it’s the address space?

  • Question 3: Am I right in thinking that whilst fubar and foo have the same value, they are completely independent and have no common address space?

  • 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-08T02:55:55+00:00Added an answer on June 8, 2026 at 2:55 am
    • Answer 1: Correct. The variable bar is a pointer, and using *bar dereferences the pointer and evaluates to what the pointer is pointing to. Realise though that it doesn’t evaluate to a [temporary] copy, but a reference to its target.

    • Answer 2: “Address space” is different from “address”; the address of a variable is simply its location in memory, whereas a program’s “address space” is all the memory it has available to use. Variables do not have address spaces, programs do. What you are seeing in the output of your program are addresses (the addresses of foo and fubar).

    • Answer 3: Yes, you are correct. They have the same value, but what happens to one will not affect the other (they are at different addresses and are therefore different objects).

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

Sidebar

Related Questions

i am using the following code(based on this http://goo.gl/5HhSx ) to calculate the difference
I'm using the following code to cause a ul based dropdown menu to open,
Using pdfbox displays an error: import java.awt import javax` Based on the following code:
I am reading the source code of the Django application blog at git://github.com/nathanborror/django-basic-apps.git .
Based on my reading, the following code: string aggregate = give + 'n'; Should
I have the following HTML code based on a tab menu format, i.e: <div
I have the following code that creates a submenu based on current document. The
In the following code, the stack-based variable 'ex' is thrown and caught in a
I have the following code to create a music playlist based on files in
Gday All, The following code displays a div based on the option that has

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.