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 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| package main
import "fmt"
var arr []int
func main() {
array1 := [3]int{1, 2, 3} fmt.Println(array1)
array2 := [...]float64{1.2, 2.1, 3.2, 4.3} fmt.Println(array2) fmt.Println(len(array2))
array3 := [3]int{1: 1, 2: 3} fmt.Println(array3)
array4 := [...]int{1: 1, 2: 2, 4: 6} fmt.Println(array4, len(array4))
array5 := [...]int{1, 2, 3} b := array5[0] fmt.Println(b) for i, v := range array5 { fmt.Println("i = ", i, "v = ", v) }
array6 := [...]int{1, 2, 3} arlen := len(array6) fmt.Println(arlen) for i := 0; i < len(array6); i++ { fmt.Println("i=", i, "v=", array6[i]) } }
|