create an array with a length in go

To create an array with a specified length in Golang, you will use the following syntax:

main.go
var arr [length]datatype
25 chars
2 lines

Here, length is the desired length of the array, and datatype is the type of data that the array will hold. For example, to create an array of length 5 with integers, you would use the following code:

main.go
var arr [5]int
15 chars
2 lines

This creates an array named arr with a length of 5, and each element in the array is of type int.

related categories

gistlibby LogSnag