1
int *p; int **pp; int a = 9; p = &a; pp = &p; cout << "&a: " << &a cout << "&p: " << &p cout << "&pp: " << &pp cout << "pp : " << pp cout << "*pp: " << *pp cout << "&*pp: " << &*pp 

&&p and &&pp aren't defined in c++ so they are wrong using, but what &*pp is meaning? Is &*pp equalent to &&a?

When the program is starting, the result is as follows:

&a: 00AEFAE4 &p: 00AEFAFC &pp: 00AEFAF0 pp : 00AEFAFC *pp: 00AEFAE4 &*pp: 00AEFAFC (=&p ???) 

On the other hand, why is &*pp equalent to &p?

7
  • C++ provides templates so that direct use of pointers can be avoided Commented Jan 24, 2018 at 5:25
  • 1
    Please post an example of the code you are asking about Commented Jan 24, 2018 at 5:26
  • Too little context to make an answer. Please expand. What code generates your output? &*pp looks like you dereference pp to p and then take the address again so effectively it is &p, but can't be sure without more information. Commented Jan 24, 2018 at 5:28
  • The code is very simple, my question is; why is &*pp equalent to &p? Commented Jan 24, 2018 at 5:36
  • Why wouldn’t it be, since *pp is p? Commented Jan 24, 2018 at 5:52

1 Answer 1

2

you asked what does &*pp means here pp is a double pointer which contains address of the pointer (*p) by writing &*pp firstly you are dereferencing value of **pp

*(pp) which will become value inside pp which is the address of pointer p by writing &(*pp) now you are trying to get address of the dereferenced value which is (address of p) that will ultimetely become address of p

in simple words where you use both of these operators together they cancel out each other and give you the value present in the pointer in this case &* will be cancelled out and you will get value of pp which is address of p i tried to make it as clear as i could.... hope that helps :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.