What is the difference between * & aPtr and & * aPtr?

I want to know what distinguishes between *&aPtrand &*aPtrwhen replacing * and and and *?

int a;   
int *aptr;  
a = 7;     
aptr=&a;

cout << &* aPtr<< *&aPtr<< endl;
+4
source share
3 answers

They have the same value, but *&aPtr- this is the value of l that refers to aPtr, whereas &*aPtr- this is the value that has the same meaning as aPtr.

+7
source

If types are primitives (integers, characters, booleans, etc.), then they will give the same value.

The difference may be the case if the operators &and *overwhelmed for a particular class. in this case, depending on the implementation, there may be a difference.

: , T* t null:

int* i = nullptr;
*&i; //ok, first takes the address of i, then dereference it, yielding a null pointer again
&*i //wrong, dereference a null pointer, yielding undefined behavior
+3

* .

,

&*aPtr

*, lvalue a , &, rvalue a. aPtr. , ,

&*aPtr = &a;

aPtr = &a;

*&aPtr

&, aPtr. *, aPtr.

,

*&aPtr = &a;

* & aPtr l aPtr.

+1
source

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


All Articles