请问一下,怎么定义个指针数组,里面的指针都是数组指针

Velpro · · 2112 次点击
``` func Test(t *testing.T) { var a [2]uintptr arr1 := [...]int{1, 2, 3, 4} arr2 := [...]string{"aaa", "bbb"} a[0] = uintptr(unsafe.Pointer(&arr1)) a[1] = uintptr(unsafe.Pointer(&arr2)) for i := 0; i < len(arr1); i++ { fmt.Println(*(*int)(unsafe.Pointer(a[0] + uintptr(i*8)))) } for i := 0; i < len(arr2); i++ { fmt.Println(*(*string)(unsafe.Pointer(a[1] + uintptr(i*16)))) } } ```
#6
更多评论
定义数组用make make([]int,10)
#1
1L指的是切片,也是常用`定义切片(切片是数组的引用)`的方法 授人以鱼不如授人以渔,定义数组的详细方法请阅读[Go 101 - 数组、切片和映射](https://gfw.go101.org/article/container.html)
#2