Written by: CSE Gyan | Last Updated: August 2026
An array is a fundamental data structure used to store a collection of elements in an organized manner. In languages such as C, an array stores elements of the same declared data type in contiguous memory locations.
Each element is identified using an index. In C, array indexing starts from 0, so the first element is stored at index 0, the second at index 1, and so on.
Arrays are useful when a program needs to work with multiple related values using a single variable name. For example, marks of students, product prices, temperatures, or a sequence of numbers can be represented using an array.
Arrays are also important because they provide the foundation for understanding several other data structures and algorithms. Their simple indexed organization makes them one of the first data structures commonly studied in programming.
An array is a data structure in which a collection of elements can be accessed using their positions or indexes. The exact behavior of an array depends on the programming language, but traditional arrays such as those used in C have a fixed declared size and store elements of one declared type.
If an array contains n elements, the indexes in a zero-based array range from 0 to n - 1.
Index: 0 1 2 3 4
+-----+-----+-----+-----+-----+
Array: | 10 | 20 | 30 | 40 | 50 |
+-----+-----+-----+-----+-----+
In this example, the value 30 is stored at index 2.
Arrays are particularly useful when a program needs to process a collection of values of the same logical kind. Instead of creating separate variables for every value, one array can represent the complete collection.
For example, instead of writing separate variables such as
mark1, mark2, and mark3, a program
can store the values in an array and process them using loops.
int marks[3] = {75, 82, 91};
This approach becomes especially useful when the number of values is large and the same operation has to be performed on many elements.
Arrays can be classified according to the number of indexes required to access their elements. The most common forms are one-dimensional, two-dimensional, and multi-dimensional arrays.
A one-dimensional array stores elements in a single sequence and uses one index to identify an element.
Index: 0 1 2 3 4
↓ ↓ ↓ ↓ ↓
+----+----+----+----+----+
| 10 | 20 | 30 | 40 | 50 |
+----+----+----+----+----+
One-dimensional arrays are commonly used for lists such as marks, prices, roll numbers, and temperature readings.
Example in C:
int marks[5] = {65, 78, 90, 82, 74};
The complete tutorial covering declaration, initialization, traversal, insertion, deletion, searching, programs, and examples is available separately:
Learn One-Dimensional Array in Detail →
A two-dimensional array organizes elements using rows and columns. Two indexes are required to identify an element: one for the row and another for the column.
Column
0 1 2
+-----+-----+-----+
0 | 10 | 20 | 30 |
+-----+-----+-----+
1 | 40 | 50 | 60 |
+-----+-----+-----+
Two-dimensional arrays are useful for matrices, tables, grids, game boards, and other data that naturally has row-and-column relationships.
Example in C:
int matrix[2][3] = {
{10, 20, 30},
{40, 50, 60}
};
For a complete explanation of rows, columns, nested loops, matrix operations, programs, and examples, see the dedicated tutorial:
Learn Two-Dimensional Array in Detail →
A multi-dimensional array uses more than two indexes. It can be useful when data has more than two dimensions, such as certain scientific, engineering, simulation, or graphics-related applications.
int data[2][2][2];
Multi-dimensional arrays should be understood as an extension of the same indexed concept rather than as a completely different data structure.
Common array operations include accessing elements, traversing the collection, searching for a value, updating an element, inserting a value, deleting a value, and sorting the elements.
Accessing means retrieving an element using its index. In a traditional array, accessing an element by a known index is generally an O(1) operation.
int arr[5] = {10, 20, 30, 40, 50};
printf("%d", arr[2]);
Output:
30
Traversal means visiting the elements one by one. A loop is commonly used to process every element.
for(int i = 0; i < 5; i++)
{
printf("%d ", arr[i]);
}
Searching determines whether a required value exists in an array and, when applicable, identifies its position. Linear Search is commonly used when the data is not arranged in a way that supports a faster search.
An existing element can be changed by assigning a new value to its index.
arr[2] = 100;
Inserting a value into a particular position may require existing elements to be shifted. Therefore, insertion in the middle of an array can require more work than direct access.
Deleting an element from the middle can also require subsequent elements to be shifted so that the logical sequence remains continuous.
Sorting arranges elements according to an order such as ascending or descending order. Different sorting algorithms have different performance characteristics.
The cost of an array operation depends on what operation is being performed and where the element is located.
| Operation | Typical Complexity | Reason |
|---|---|---|
| Access by Index | O(1) | Index directly identifies the element. |
| Update by Index | O(1) | The element can be reached directly by index. |
| Traversal | O(n) | Every element may need to be visited. |
| Linear Search | O(n) | Elements may need to be checked one by one. |
| Insertion in Middle | O(n) | Elements may need to be shifted. |
| Deletion from Middle | O(n) | Remaining elements may need to be shifted. |
These are general asymptotic costs. The actual operation cost depends on the specific implementation and the position of the affected element.
Arrays and linked lists both store collections of elements, but they organize memory differently. The choice between them depends on the required operations and application constraints.
| Feature | Array | Linked List |
|---|---|---|
| Memory Organization | Contiguous in traditional C arrays | Nodes can be stored at different memory locations |
| Direct Access | Efficient using an index | Requires traversal |
| Insertion in Middle | May require shifting | Can be efficient after reaching the required position |
| Deletion in Middle | May require shifting | Can be efficient after reaching the required node |
| Memory Overhead | Low for the elements themselves | Additional links/pointers are required |
Arrays are useful in many programming and computing tasks where a collection of related values needs to be stored and processed.
An array is an indexed data structure used to store a collection of elements. In a traditional C array, the elements have one declared data type and are stored contiguously.
An index identifies the position of an element. In C, indexing normally starts from 0.
Accessing an element by a known index is generally O(1) in a traditional array.
Inserting an element into the middle may require existing elements to be shifted to make space.
A one-dimensional array uses one index and represents a sequence of elements, while a two-dimensional array uses row and column indexes and represents data in a grid-like structure.
No. A traditional fixed-size C array does not automatically resize itself. Dynamic memory techniques or another data structure can be used when the required size changes.
Arrays are used for storing lists of values, matrix data, sensor readings, marks, prices, and intermediate data used by algorithms.
Arrays are one of the fundamental data structures used for organizing collections of related values. Their indexed access, simple representation, and efficient sequential processing make them important in programming and algorithm design.
Understanding array operations and their complexity provides a strong foundation for studying searching, sorting, linked lists, stacks, queues, trees, graphs, and other data structures.