I'm aware of what difference in Go pointer's address.
var int *a = new(int)
I can define pointer variable like this. When I check this variable's address, I found out another address.
fmt.Println(a, &a)
I'd like to know what difference in those address.enter code here
a
is a variable of pointer type, which means the data it holds is a memory address. So printing a
prints the memory address it holds, the address of the variable it points to.
And a
being a variable, it is stored somewhere in memory, a
itself also has an address and &a
is that address.
So you have 2 variables: a
and the one created by new(int)
, whose address is returned by new()
and which address we store in a
.
Please read this for a clear and short introduction to pointers:
Dave Cheney: Understand Go pointers in less than 800 words or your money back