0
& with a pointer
I understand that & is used to get the address of a variable, what I'm wondering is what is obtained when an & prefaces a pointer, will it return the address of the variable it points to or the pointers own address. I tried programming it in gdb online compiler in plain C and got two different addresses outputted.
2 Respuestas
+ 2
A pointer is a variable itself, so when you use the & operator with it, you get the pointer's own address.
+ 1
Suppose there is variable named a stored at address 1000 and having value 10.
And a pointer variable named b which is actually stored at address 2000 points towards a.
Address | Variable | Value
1000 | a | 10
2000 | b | 1000
Using & operator will give address of that variable.