how to print the memory address of a slice and that of its underlying array
tags: learning go programming
content
slice := []int{1, 2, 3}
fmt.Printf("type of slice: %T", slice)
// prints []int, slice is NOT a pointer
fmt.Printf("memory addr of slice: %p", &slice)
// prints memory address of slice
fmt.Printf("memory addr of underlying array: %p", slice)
// prints memory address of underlying array
fmt.Println("memory addr of underlying array:", &slice[0])%pis a special thing.sis a slice, not a pointer- but when a slice is passed to
%p,fmtprints out the memory address of its underlying array
%p, sliceand&slice[0]are literally the same%p, &slice[0]is the same too!