在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
概述 package main import ( "fmt" ) func main() { //一维数组 var arr_1 [5] int fmt.Println(arr_1) var arr_2 = [5] int {1, 2, 3, 4, 5} fmt.Println(arr_2) arr_3 := [5] int {1, 2, 3, 4, 5} fmt.Println(arr_3) arr_4 := [...] int {1, 2, 3, 4, 5, 6} fmt.Println(arr_4) arr_5 := [5] int {0:3, 1:5, 4:6} fmt.Println(arr_5) //二维数组 var arr_6 = [3][5] int {{1, 2, 3, 4, 5}, {9, 8, 7, 6, 5}, {3, 4, 5, 6, 7}} fmt.Println(arr_6) arr_7 := [3][5] int {{1, 2, 3, 4, 5}, {9, 8, 7, 6, 5}, {3, 4, 5, 6, 7}} fmt.Println(arr_7) arr_8 := [...][5] int {{1, 2, 3, 4, 5}, {9, 8, 7, 6, 5}, {0:3, 1:5, 4:6}} fmt.Println(arr_8) }
var arr_1 = [5] int {1, 2, 3, 4, 5} arr_1[5] = 6 fmt.Println(arr_1)
invalid array index 5 (out of bounds for 5-element array)
//demo_5.go package main import ( "fmt" ) func main() { var arr = [5] int {1, 2, 3, 4, 5} modifyArr(arr) fmt.Println(arr) } func modifyArr(a [5] int) { a[1] = 20 }
//demo_6.go package main import ( "fmt" ) func main() { var arr = [5] int {1, 2, 3, 4, 5} modifyArr(&arr) fmt.Println(arr) } func modifyArr(a *[5] int) { a[1] = 20 }
var arr = [5] int {1, 2, 3, 4, 5} var arr_1 [5] int = arr var arr_2 [6] int = arr
cannot use arr (type [5]int) as type [6]int in assignment
|
请发表评论