I am trying to declare an array like below
arr := [
[0, 0],
[1, 2],
[2, 4],
]
// type: [][]int
but the type I am getting from the inference is [][]int
, instead I want to declare [][]float32
. When I tried the below syntax I got [][]f64
.
arr := [
[0.0, 0],
[1.0, 2],
[2.0, 4],
]
// type: [][]f64
what I want is a simple way like the below, we can declare in c
float arr[][2] = {
{0, 0},
{1, 2},
{2, 4}
};
// type: f32
I was reading the v docs but couldn't find any information about how to give explicit type in the array.
V will "automagically" infer types by the type of the first element:
Another, shorter, way is to initialize it first, but then you will not have initial values: