I'm new to GO. There is the problem I'm facing.
The function takes a 2D array in arbitrary size as argument:
func PrintArray(a [][]string) {
for _, v1 := range a {
for _, v2 := range v1 {
fmt.Printf("%s ", v2)
}
fmt.Printf("\n")
}
}
As you can see, since the nested loop uses range. The size of the array really doesn't matter.
But when I try to call this function:
a := [3][2]string{
{"line", "tiger"},
{"cat", "dog"},
{"pigeon", "hamster"},
}
PrintArray(a[:])
It complains about:
cannot use a[:] (type [][2]string) as type [][]string in argument to PrintArray
However, it won't compile with a[:][:] either.
What is the correct way to define a multidimensional array in arbitrary size in GO lang?