1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package main
import ( "fmt" )
func main() { var a = [3]int{1, 1, 1} // 数组
var i, j ,k int = 2, 2, 2 var c [3] * int = [3]* int {&i, &j, &k} // 指针数组,这是一个数组,里面存的都是指针 var d * [3] int = &a // 数组指针,这是一个指针,指向一个 [3]int 类型的数组 // 必须制定数组长度否则会 => cannot use &a (type *[3]int) as type *[]int in assignment var e ** [3] int = &d // 数组指针的指针,指向一个 [3]int 类型的数组指针 fmt.Println("c[0] =", c[0], "c[1] =", c[1],"c[2] =", c[2]) fmt.Println("*c[0] =", *c[0], "*c[1] =", *c[1],"*c[2] =", *c[2]) fmt.Println("d =", d) fmt.Println("*d =", *d) fmt.Println("d[0] =", d[0], "d[1] =", d[1],"d[2] =", d[2]) fmt.Println("(*d)[0] =", (*d)[0], "(*d)[1] =", (*d)[1],"(*d)[2] =", (*d)[2])
fmt.Println("e =", e) fmt.Println("*e =", *e) fmt.Println("**e =", **e) }
|