Junior — Middle
Is it possible to declare an array by assigning it through a variable?
sobes.tech AI
Answer from AI
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 on assignment).
Example of declaring an array and assigning via a variable:
var arr [3]int = [3]int{1, 2, 3}
var anotherArr [3]int
anotherArr = arr // copying array
You can also use slices, which are more flexible and usually preferred:
var slice []int = []int{1, 2, 3}
var anotherSlice []int
anotherSlice = slice // assigning slice (reference to array)
Thus, yes, you can declare an array and assign it via a variable, but consider the copying and size characteristics.