How to Print the Memory Address of a Slice in Go
Created
Modified
Using fmt.Printf Function
Pointer:
%p base 16 notation, with leading 0x. The %b, %d, %o, %x and %X verbs also work with pointers, formatting the value exactly as if it were an nteger.
See the following example:
package main
import "fmt"
func main() {
a := []int{1, 2, 3}
b := a[:]
fmt.Printf("&a: %p\n", &a)
fmt.Printf("&b: %p\n", &b)
fmt.Printf(" a: %p\n", a)
}
&a: 0xc0000ac018 &b: 0xc0000ac030 a: 0xc0000ba000