&
is the address operator, evaluating it results in a memory address, which when passed to the fmt
package, usually the memory address is printed in hexadecimal format ("base 16 notation, with leading 0x").
A memory address is just that: a memory address. It doesn't matter if it's an address of an int
variable or a string
, or a variable of a pointer type. When printed, they all look the "same".
The address operator:
For an operand x
of type T
, the address operation &x
generates a pointer of type *T
to x
.
So the address operator gives you a pointer value which when you dereference, you get back the original value.
&b
will be an address of the variable b
, of type *int
, which when you dereference: *b
will give you (the value of) b
.
&i
will be the address of the variable i
, of type **int
, which when you dereference: *i
will give you the value of i
which is the address of b
. So if you also dereference that: **(&i)
, that will also give you (the value of) b
.