Is it possible to a)define b)initialize a new multidimensional array using an existing array, like in following code instead of var b [2][3]int
, just saying something like var b [2]a
?
Using a's type whatever it is, instead of hardcoding it (which misses the point of using [...] for a).
And perhaps handling initialization=copying of values at the same time?
package main
func main () {
a := [...]int{4,5,6}
var b [2][3]int
b[0],b[1] = a,a
}
(I'm aware of ease and convenience of slices, but this question is about understanding arrays.)
Edit: can't believe I forgot about var b [2][len(a)]int
, beginner's brain freeze. One line answer would be var b = [2][len(a)]int{a,a}
. That's a type conversion, right?