我有一定的C经验,并且对golang完全陌生。
func learnArraySlice() {
intarr := [5]int{12, 34, 55, 66, 43}
slice := intarr[:]
fmt.Printf("the len is %d and cap is %d \n", len(slice), cap(slice))
fmt.Printf("address of slice 0x%x add of Arr 0x%x \n", &slice, &intarr)
}
现在在golang slice中是array的引用,其中包含指向slice的数组len和slice的上限的指针,但是该slice也将分配在内存中,我想打印该内存的地址。但是无法做到这一点。
最佳答案
fmt.Printf("address of slice %p add of Arr %p \n", &slice, &intarr)
%p
将打印地址。关于go - 如何在Golang中打印 slice 的内存地址?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22811138/