It's not the address size what is different, it's the size (length) of the hexadecimal representation as you printed it.
All addresses you print on the Go Playground are 4 bytes, but if the first bytes (or bits) are zero, they are not printed.
Also if you take a closer look, addresses of your global vars have 6 hexa digits, pointers allocated and returned by new()
have 8 hexa digits. This is because those int
s (returned by new()
) are allocated on the heap with bigger offset (and thus "bigger" memory address).
For example:
var i, j int32 = 123, 123000
fmt.Printf("%x %x
", i, j)
Prints 7b 1e078
even though both numbers are 4 bytes long (32 bits). You may use a format string to add padding 0
s like this:
fmt.Printf("%08x %08x
", i, j)
Which results in 0000007b 0001e078
but this will always pad to 8 digits even if i
or j
would be "less" than 4 bytes (e.g. int16
), so this padding won't tell you if they are of different sizes.