golang with a slice of the array

Array

Array can store a plurality of the same type of data, a data type is an array, in Go, the array is a value type.

Array definition:

  var array name [array size] Data Type

  var in [5] int

  Initial value a [0] = 1 a [1] = 30 ....

Including an array layout

 

 to sum up:

  1) address of the array can be obtained by an array of names & intArr

  Address of the first element 2) of the array, the array is the first address

  3) address of each element of the array interval is determined depending on the type of array, such as int64 -> 8 int32 -> 4 ....

Array traversal:

  for-range

    Go This is a language unique structure, it can be used to traverse the array element access

    usage:

      for index, value := range array01 {

      ...

      }

Notes and usage details:

  1) An array is a combination of a plurality of the same data type, an array declaration once / defined, its length is fixed and can not dynamically change

  2) var arr [] int time slice is a slice arr

  3) elements in the array may be any type of data, including the value and reference types, but do not mix

  4) create an array, if no assignment has a default value of 0

  5) Step 1. declare an array using an array of open space and 2. assignment 3. Using an array of individual elements to the array

  6) the subscript of the array is started from 0

  7) array subscript must be used within a specified range, otherwise the reported panic: array bounds

  8) Go genus array value types, the default value is transmitted, thus a value copy do not affect each other between the array 

  9) To the other function, to modify the original array, can pass by reference (pointer mode),

  10) is a part of the length of the array type, the transfer function parameters to consider when the length of the array.

Four kinds initialize an array of ways:

was numsArray01 [3] = int [3] int {1, 2, 3 }
was numsArray02 = [3] int {1, 2, 3 }
was numsArray03 = [...] int {6, 7, 8 }
var names = [3]string{1: "tom", 0: "jack", 2: "marry"}

 

Guess you like

Origin www.cnblogs.com/xiangxiaolin/p/11817041.html