-18 using multidimensional arrays road golang learning

package main

func main() {
   // declare an array of four rows and two columns
   var array[4][2]int
   // use the array literal to declare and initialize a two-dimensional array of type integer
   array = [4][2]int{{10,11},{20,21},{30,31},{40,41}}
   // declare and initialize the array index elements 1 and 3
   array = [4][2]int{1:{20,21},3:{40,41}}
   // declare and initialize the array elements specified
   array = [4][2]int{1:{0:20},3:{1:41}}

   // declare a two-dimensional array
   var array_1[2][2]int
   // set the integer value of each element
   array_1[0][0] = 10
   array_1[0][1] = 20
   array_1[1][0] = 30
   array_1[1][1] = 40

   // declare two dimensional array of integers
   var array1[2][2]int
   var array2[2][2]int
   // assignment
   array1[0][0] = 10
   array1[0][1] = 20
   array1[1][0] = 30
   array1[1][1] = 40
   // will assign array2 array1
   array2 = array1

   // The index of array1 is copied to a new array of the same type for the dimension of 1
   was array3 [2] [2] int
   array3 [1] = array1 [1]
   // Copy the integer value specified in the array to a new integer variable
   var value int = array1[1][0]


}
发布了63 篇原创文章 · 获赞 0 · 访问量 1223

Guess you like

Origin blog.csdn.net/qq_37463791/article/details/103429979