OneBite.Dev - Coding blog in a bite size

declare an array in Go

Code snippet on how to declare an array in Go

  array := [3]int{1, 2, 3}

This code is used to define an array of type integer with three elements containing the values 1, 2 and 3 respectively. The variable ‘array’ is assigned to the array containing the three elements. The array is declared using the ‘[3]int’ syntax which means that the array is an array of integers with a length of 3. The values contained in the array are specified within the curly braces. The first value is 1, the second value is 2 and the third value is 3. Finally, the variable is assigned to the array. This code can be used to declare any type of array with a fixed length and values.

go