Arrays and Slices
Array An array has a fixed size. Since arrays has static size, its memory is allocated only once. If ellipsis "..." is used in-place of size, the length of the array is inferred from the number of values declared. Syntax var array_name [capacity]type var array_name = [capacity]datatype{values} var array_name = [...]datatype{values} Example var characters := [...]string{"Sheldon", "Leonard", "Wolowitz", "Rajesh"} primes := [5]{2, 3, 5, 7, 11} Slices A slice is dynamically sized. A slice does not store any data. It describes the portion of the underlying array. Changing the elements of the slice modifies the underlying array and other slices that share the same underlying array will also have the changes. A slice literal is similar to an array literal without the length. Internally, it creates the array and builds a slice on top of it. For an array [10]int , the slice equivalents are array[0:10], array[:10], array[0:], array[:] The leng...