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

C++CServer Side ProgrammingProgramming

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
raja
Published on 29-Mar-2019 11:09:10
Advertisements