1)
For below slice declaration,
var a [][3]string
creates a single slice(a
) that points to array of 3 strings, len(a) = 3
and cap(a) =3
but not cap(a) >= 3
a = make([][3]string, 5)
creates 5 slices, where each slice(say a[0]
) points to array of 3 strings, len(a[0]) = 3
and cap(a[0]) = 3
2)
For slice declaration,
var b [][3][6]string
creates a single slice(b
) that points to 3 arrays of 6 strings each, where len(b) = 3
and cap(b) =3
b = make([][3][6]string, 5)
creates 5 slices, where each slice(say b[0]
) points to 3 arrays of 6 strings each
In both cases, after making slices, I said, creates 5 slices,
Considering the syntax, below are my two questions,
a = make([][3]string, 5)
My question:
1)
Is it 5 slices, where each slice(a[0]
) is array of 3 strings?
or
Is it a single slice(a
) pointing to 5 arrays of 3 strings each?
2)
How do I know the type of an element? slice or array?
1) In such scenarios, "array of" terminology has to be cautiously used.
2) There are no implicit pointers involved in GO unlike C