create an array with a length of type float in go

To create an array with a length of type float in Go, you can use the following code:

main.go
myArray := [5]float64{1.0, 2.0, 3.0, 4.0, 5.0}
47 chars
2 lines

In this example, we are creating an array called myArray with a length of 5 and a type of float64. We are also initializing it with the values 1.0, 2.0, 3.0, 4.0, and 5.0.

Alternatively, you can create an empty array of type float64 with a length of 5 and then assign values to it later like this:

main.go
var myArray [5]float64
myArray[0] = 1.0
myArray[1] = 2.0
myArray[2] = 3.0
myArray[3] = 4.0
myArray[4] = 5.0
108 chars
7 lines

In this example, we are creating an empty array of type float64 with a length of 5 called myArray. Then, we are assigning values to each index of the array using indexing notation.

related categories

gistlibby LogSnag