icz*_*cza 6
reflect.SliceHeader
type SliceHeader struct {
Data uintptr
Len int
Cap int
}
fmt%p
%p address of 0th element in base 16 notation, with leading 0x
%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 integer.
%p&slice%p&slice
要验证,还要显式打印第0个元素的地址:
fmt.Printf("address of slice %p \n", slice)
fmt.Printf("address of slice %p \n", &slice)
fmt.Println(&slice[0])
输出将是(在Go Playground上尝试):
address of slice 0x170460
address of slice 0x17d0b8
0x170460
&slice[0]%pslice
现在让我们修改示例以使用我们自己的后备数组:
var arr = [4]int{1, 2, 3, 4}
var slice = arr[:]
所以这样我们也可以打印支持数组的第0个元素的地址:
fmt.Printf("address of slice %p \n", slice)
fmt.Printf("address of slice %p \n", &slice)
fmt.Println(&slice[0])
fmt.Printf("Array 0th: %p", &arr[0])
输出(在Go Playground上试试):
address of slice 0x170460
address of slice 0x183e78
0x170460
Array 0th: 0x170460
slice%p