/əˈreɪ/
noun … “Contiguous collection of elements.”
Array is a data structure consisting of a sequence of elements stored in contiguous memory locations, each identified by an index or key. Arrays allow efficient access, insertion, and modification of elements using indices and are foundational in programming for implementing lists, matrices, and buffers. They can hold primitive types, objects, or other arrays (multidimensional arrays).
Key characteristics of Array include:
- Contiguous memory: elements are stored sequentially to enable fast index-based access.
- Fixed size: in many languages, the size is defined at creation; dynamic arrays can resize automatically.
- Indexed access: elements are accessed via integer indices, often starting from zero.
- Integration with pointers: in low-level languages, arrays are closely linked to pointers and support pointer arithmetic for traversal.
- Multidimensional support: arrays can be organized into two or more dimensions for tables or matrices.
Workflow example: Iterating over an array in C:
int array[5] = {10, 20, 30, 40, 50}
for int i = 0..4:
printf("%d", array[i])
Here, each element is accessed sequentially using its index, illustrating the efficiency of arrays for ordered data storage and retrieval.
Conceptually, Array is like a row of mailboxes: each box has a specific number (index) and allows direct access to its contents without checking the others.
See Pointer, Memory, Heap, Stack, Dynamic Array.