My Go Tutorial

Go Array

Go arrays are containers for storing sequenced values of the same type that are numerically indexed. 

Arrays are useful when planning the detailed layout of memory and sometimes can help avoid allocation.

[N]Type{value1, value2, ..., valueN}
[...]Type{value1, value2, ..., valueN}

Planning to store a student who has a maximum of 5 subjects scores and is not a dynamic subject.

myStudentscores := [5]int{50,90,80,60,70}
The compiler will have a fixed memory allocation 5 individual integer size for myStudentscores with initializing values. This avoids of allocation of memory that gets unused.
Note: [5]int it length is part of a type. So [4]int is not the same type [5]int. As result equal operation comparison of both result in compile time error of type mismatch. 

Array Methods


Reading value of an Array

for x in range <array_name>