Why does this print a value...?

So let's say I have this code...

1
2
3
int a = 5;
int& myReference = a;
int* myPointer = &myReference;


Why does...

std::cout << *myPointer;

...print '5' to the screen and not a memory address?
Last edited on
You are dereferencing the pointer, so you get the value of whatever was at that address; namely, the number 5. The reference is not necessary at all; the code is identical in function to:
1
2
int a = 5;
int* myPointer = &a;
ohhh... crystal clear when you remove line 2 to simplify. Thanks.
Topic archived. No new replies allowed.