Why does indexes start with zero?

Showing Answers 1 - 3 of 3 Answers

M. PAVAN KUMAR REDDY

  • Jan 18th, 2007
 

In order to access an element in an array, we will use index.

Let us declare:

int a[20];

Here a is the base address of array.

To access a[i], the compiler adds index to the array base address i.e. a[i] is accessed by the compiler as *(a+i). So, if you have to access first element in an array i.e. a[0], compiler replaces a[0] with *(a+0). This is called adding offset to base address. If you say a[1], compiler gives you *(a+1) i.e. second element of the array. That's why index has to start with zero.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions