September 2017
Intermediate to advanced
466 pages
9h 33m
English
Arrays are the most popular data structure due to their speed and are supported by almost all programming languages. You can declare an array in Go as follows:
myArray := [4]int{1, 2, 4, -4}
Should you wish to declare an array with two or three dimensions, you can use the following notation:
twoD := [3][3]int{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
threeD := [2][2][2]int{{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}
The index of the first element of each dimension of an array is 0, the index of the second element of each dimension is 1, and so on. Accessing, assigning, or printing a single element from one of the previous three arrays can also be done easily:
myArray[0] twoD[1][2] = 15 threeD[0][1][1] = -1
The most common way to access all the elements ...
Read now
Unlock full access