How to print the memory address of a slice in Golang?

前端 未结 3 513
长情又很酷
长情又很酷 2021-02-04 01:34

I have some experience in C and I am totally new to golang.

func learnArraySlice() {
  intarr := [5]int{12, 34, 55, 66, 43}
  slice := intarr[:]
  fmt.Printf(\"t         


        
3条回答
  •  一整个雨季
    2021-02-04 02:36

    Slices and their elements are addressable:

    s := make([]int, 10)
    fmt.Printf("Addr of first element: %p\n", &s[0])
    fmt.Printf("Addr of slice itself:  %p\n", &s)
    

提交回复
热议问题