简体   繁体   中英

What's meaning of &&pointer or &*(pointer_to_pointer) in C++

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 ?

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 pi tried to make it as clear as i could.... hope that helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM