# Why array index starts from zero ?

Prerequisite : Pointers in C/C++

Consider int arr[100]. The answer lies in the fact how the compiler interprets arr[i] ( 0<=i<100).

arr[i] is interpreted as *(arr + i). Now, arr is the address of array or address of 0th index element of array. So, address of next element in array is arr + 1 (because elements in array are stored in consecutive memory locations), further address of next location is arr + 2 and so on . Going with above arguments, arr + i means address at i distance away from starting element of array. Therefore, going by this definition, i will be zero for starting element of array because starting element is at 0 distance away from starting element of array. To fit this definition of arr[i], indexing of array starts from 0.

`#include<iostream> ` `using` `namespace` `std; ` ` ` `int` `main() ` `{ ` ` ` `int` `arr[] = {1, 2, 3, 4}; ` ` ` ` ` `// Below two statements mean same thing ` ` ` `cout << *(arr + 1) << ` `" "` `; ` ` ` `cout << arr[1] << ` `" "` `; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

2 2

The conclusion is, we need random access in array. To provide random access, compilers use pointer arithmetic to reach i-th element.

## Recommended Posts:

- Queries for number of distinct elements from a given index till last index in an array
- Rearrange array such that even index elements are smaller and odd index elements are greater
- Minimum cost to reach end of array array when a maximum jump of K index is allowed
- Longest alternating sub-array starting from every index in a Binary Array
- Construct an array from XOR of all elements of array except element at same index
- Equilibrium index of an array
- Sum of the elements from index L to R in an array when arr[i] = i * (-1)^i
- Sort the array in a given index range
- Find the index of first 1 in a sorted array of 0's and 1's
- Minimum value to add to arr[i] so that an array can be split at index i with equal sum
- Array Index with same count of even or odd numbers on both sides
- Delete array element in given index range [L - R]
- Smallest index in the given array that satisfies the given condition
- Queries for bitwise OR in the index range [L, R] of the given array
- Queries for bitwise AND in the index range [L, R] of the given array

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.