Intern
What is an array?
sobes.tech AI
Answer from AI
An array is an ordered collection of elements of the same type with a fixed size.
// declaring an array of 5 integers
var a [5]int
// assigning values to elements
a[0] = 10
a[4] = 50
// accessing elements
x := a[0] // x = 10
Main characteristics:
- Fixed size: The size of the array is determined at its declaration and cannot be changed during runtime.
- Elements of the same type: All elements of the array must have the same data type.
- Sequential storage: Array elements are stored sequentially in memory, providing fast access by index.
- Indexing: Access to elements is done by a numeric index, starting from 0.