Arrays in Go has a fixed size.
Note that arrays are immutable.
Immutable means that the object created cannot be changed or modified after its creation.
We can obtain the length of an array using the
len function. For example,
len(a) returns the length of an array
We can address till the length of the array, but tryig to access beyond this length, will return an "arrays out of bounds" error.
We can also append to an array, i.e. add new elements. However, since arrays are immutable, appending to an array will create a new instance. This means that the entire original array is copied and a new element is added to it.
Arrays have contiguous memory which makes accessing elements faster.
Defining an array:
var a int. This creates an array of length 4, initialized to all zeroes.
Arrays are values. Unlike C, arrays are not pointers to the first array element. When we pass around an array value, we are passing by value (we make a copy). We could alternatively pass a pointer to the array.
We can think of array as a sort of
struct with indexes.