Junior — Middle
Can you explain what is meant by the concept of an array in programming?
sobes.tech AI
Answer from AI
An array in programming is a data structure that stores a fixed number of elements of the same type in contiguous memory locations.
Main characteristics of an array:
- Elements are indexed by integers, usually starting from 0.
- Access to elements is done in constant time (O(1)).
- The size of the array is fixed upon creation and does not change.
Example of an array in C#:
int[] numbers = new int[3];
numbers[0] = 10;
numbers[1] = 20;
numbers[2] = 30;
Console.WriteLine(numbers[1]); // Outputs 20
Arrays are convenient for storing and quickly accessing a set of homogeneous data.