var nameList [56]string // 数组指针地址与数据第一个值地址相同
fmt.Printf("nameLists数组的内存地址为%p\n", &nameList)
fmt.Printf("nameList数组中第一个元素的地址为%p\n", &nameList[0])
fmt.Printf("nameList数组中第二个元素的地址为%p\n", &nameList[1])
打印地址:
nameLists数组的内存地址为0xc000123880
nameList数组中第一个元素的地址为0xc000123880
nameList数组中第二个元素的地址为0xc000123890
ageSlice := make([]int, 56) // 底层数据的指针与底层数组第一个值地址相同 %p ageSlice = &ageSlice[0]
fmt.Printf("age_slice切片变量本身的内存地址为%p,底层地址:%p\n", &ageSlice, ageSlice)
fmt.Printf("age_slice切片中第一个元素的地址为%p\n", &ageSlice[0])
fmt.Printf("age_slice切片中第二个元素的地址为%p\n", &ageSlice[1])
打印地址:
ageSlice切片变量本身的内存地址为0xc000008fa8,底层数组地址:0xc000220000
ageSlice切片中第一个元素的地址为0xc000220000
ageSlice切片中第二个元素的地址为0xc000220008