C ++ pointer, the initial question

I just want to ask a question to beginners ...

here I made some code to understand the concept / main pointer:

int a=1;
int *b=&a;
int **c = &b;
int ***d = &c;

cout << &*(&*d) << endl;

Can someone explain to me why it &*(&*d)returns the address "c" instead of the address "b"? I also tried type code &*(&*(&*(&*(&*d)))), but it saves the return address "c"

Many thanks:)

+3
source share
5 answers

Because it &*cancels each other out. *dereferencing dthat gives meaning c. And then &indicates the address cor value d.

+4
source

& * . , *. , **d.

+3

: * / , & / .

+1

* , . & ; addressof.

, &*d d c, *d, b **d, ***d.

0

If xis a variable, then &*xnot exactly equal x. The former is rvalue, and the latter is lvalue. *&x, on the other hand, always matches x, since both expressions are lvalues.

0
source

Source: https://habr.com/ru/post/1739097/


All Articles