golang指向数组指针
定义语法
var ptr[Max]*int
实例代码
func main() {
var a = [3]int{1, 2, 3}
var ap [3]*int
fmt.Printf("ap: %v\n", ap)
for i := 0; i < len(a); i++ {
ap[i] = &a[i]
}
fmt.Printf("ap: %v\n", ap)
for i := 0; i < len(ap); i++ {
fmt.Printf("ap[i]: %v\n", *ap[i])
}
}
输出结果:
ap: [<nil> <nil> <nil>]
ap: [0xc000014198 0xc0000141a0 0xc0000141a8]
ap[i]: 1
ap[i]: 2
ap[i]: 3