
LESSON CONTENT
Indexing is the process of accessing a specific position inside an array. Each element is stored at a numbered position called an index. This index lets you read or modify that element directly.
Most programming languages use zero-based indexing. This means the first element is at index 0, the second at index 1, and so on. If an array contains n elements, the valid index range is 0 to n − 1.
Given the array:
[12, 45, 77, 30]
Indexes map to values like this:
Arrays store elements in contiguous memory. Because of this, the computer can calculate the exact location of any element instantly, making indexing an O(1) constant-time operation.
If you attempt to access an index outside the valid range, the program will throw an error. Always make sure the index is within the array’s bounds.