0
cout p and &p gives two different memory addresses, why?
Using this example code from dynamic memory section if I cout both p and &p I get two different memory addresses, can someone tell me why that might be? Thanks :) int *p = new int; *p = 5;
2 Answers
+ 13
When you cout p, you get the address p is storing (so in this case, wherever the 5 is it's pointing to).
When you cout &p, you see the address of where p is stored.
+ 9
As a pointer, p stores the address of other variables. This is shown by printing the address stored inside the pointer p. The pointer itself, has memory allocated to it. &p would return the address of the pointer itself.