Slices are far more efficient than Arrays in Go. Assigning one array to another copies all the elements while in Slice it refers to the underlying Array. There are major differences between the ways arrays work in
Go and C. In Go,-
Arrays are values. Assigning one array to another copies all the elements.- In particular, if you pass an
array to a function, it will receive a copy of the array, not a pointer to it.- The size of an
array is part of its type. The types [10]int and [20]int are distinct.*NOTE:* The value property can be useful but also expensive; if you want C-like behavior and efficiency, you can pass a pointer to the array.
Read more about
arrays and slices here:- https://golang.org/doc/effective_go.html#arrays
#go #arrays #slices
go.dev
Effective Go - The Go Programming Language