Junior — Middle
Kas on võimalik deklareerida massiiv, määrates selle muutujaga?
sobes.tech AI
Vastus AI-lt
In Go, you can declare an array and assign it via a variable, but it is important to understand that arrays in Go have a fixed size and are value types (copied during assignment).
Example of declaring an array and assigning it via a variable:
var arr [3]int = [3]int{1, 2, 3}
var anotherArr [3]int
anotherArr = arr // copying the array
You can also use slices, which are more flexible and generally preferred:
var slice []int = []int{1, 2, 3}
var anotherSlice []int
anotherSlice = slice // assigning a slice (reference to the array)
So, yes, you can declare an array and assign it via a variable, but you should consider the copying and size characteristics.