【Go】array

Arrays are the basic structure in programming languages

array

array is defined by [n], such as

1
2
var arr [10] int
arr[0] = 21

The brackets indicate the length of the array. The size of the array cannot be changed, followed by the type of storage.

Assign or index elements of the array, you can use []

Arrays are value types, assignments between arrays (such as function arguments), assignment of values, non-references or pointers

Array declaration, initialization

1
2
3
4
5
6
7
8
9
10
// Declare an array a of length 3 with an initial value of 1, 2, 3
a: = [3] int {1, 2, 3}

// or, go automatically counts the number of elements
b: = [...] int {1, 2, 3}

// Multidimensional Arrays
c: = [2] [2] int {[...] int {1, 2}, [2] int {3, 4}}
// or
d: = [2] [2] int {{1, 2}, {3, 4}}
Persist in original technology sharing, your support will encourage me to continue to create!