douya2982 2014-04-02 04:13
浏览 495
已采纳

在golang中打印切片的地址

I have some exp in C and i am totally new to golang

func learnArraySlice() {
intarr := [5]int{12, 34, 55, 66, 43}
slice := intarr[:]
fmt.Printf("the len is %d and cap is %d 
", len(slice), cap(slice))
fmt.Printf("address of slice 0x%x add of Arr 0x%x 
", &slice, &intarr)

}

Now in golang slice is a reference of array which contains the pointer to an array len of slice and cap of slice but this slice will also be allocated in memory and i want to print the address of that memory. But unable to do that.

  • 写回答

3条回答 默认 最新

  • dongzouqie4220 2014-04-02 04:18
    关注

    http://golang.org/pkg/fmt/

    fmt.Printf("address of slice %p add of Arr %p 
    ", &slice, &intarr)
    

    %p will print the address.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?