Why C/C++ array index starts from zero?


As Array index starts with 0, so a[i] can be implemented as *(a + i).

If Array index starts with 1 then a[i] will be implemented as *(a+i-1) which will be time consuming during compilation and the performance of the program will also be effected.

So, it is better to start index of the array from 0.

A simple program of array is given -

Example Code

int main() {
   int array[5] = {7, 7, 7, 6, 6};
   for (int i = 0; i < 5; i++)
      cout << *(array + i);
   return 0;
}

Output

7 7 7 6 6

Updated on: 30-Jul-2019

591 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements