Arrays
Last updated
Was this helpful?
Last updated
Was this helpful?
An array in Go is a fixed-length data type that contains a contiguous block of elements of the same type. This could be a built-in type such as integers and strings, or it can be a struct type.
The type [n]T
is an array of n
values of type T
.
An array's length is part of its type, so arrays cannot be resized.
Arrays are efficient data structures because the memory is laid out in sequence.
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.
Copying an array of pointers copies the pointer values and not the values that the pointers are pointing to.
Если тип элементов массива является сравниваемым, то таким же и является тип массива, так что мы можем сравнить два массива такого типа непосредственно при помощи оператора ==
.
Passing an array between functions can be an expensive operation in terms of memory and performance. When you pass variables between functions, they’re always passed by value. When your variable is an array, this means the entire array, regardless of its size, is copied and passed to the function. You can pass a pointer to the array.