When x is a L-value (let’s say a variable), then the following identity holds:
x == *(&x)
This is quite easy to explain, because &x is a pointer to x and the dereference operator * applied to &x will then of course return x.
Now I am wondering if the converse makes sense. To be precise I am wondering if
p == &(*p)
when p is a non-dangling pointer.
This seems to make sense, because *p is itself a L-value (a value which has an adress), because we already have the pointer (=adress) p to it. So you only need to know, that such pointers are unique, because then &(*p) has no other chance as to be p.
So when both identities are true you can say, that, mathematically, * and & are inverse functions of one another.
Am I correct? Are there any possible exceptions to this alleged rules?
When
pis an object pointer,&*pis equivalent top. The evaluation of*pdoesn’t occur and this is guaranteed by the C Standard.Here is the relevant paragraph of the Standard:
EDIT: After @ldav1s comment, I changed the word pointer to object pointer. Indeed if
pis of typevoid *, then&*pis invalid. For information, this has been discussed by the C Committee in Defect Report #102: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_012.html