Why array indexes are zero based in most programming languages?

C++, C#, C, D, Java,... are zero based.

Matlab is the only language I know that begin at 1.


Arrays are zero based in c and c++ as the represent the offset from the beginning of the list of the item.

These two lines have identical result in c.

anArray[3] = 4;
*(anArray +3) = 4; 

The first is the standard indexer the second takes the pointer adds three to id and then dereffrences it. Which is the same as the indexer.


Well, consider Dijkstra's famous article, Why numbering should start at zero. He argues that numbering should start at 0 because it means that the valid indexes into an array can be described as 0 <= i < N. This is clearly more appealing than 1 <= i < N + 1, on an aesthetic level.

(One could ask, "why not say 0 < i <= N", but he argues against that, too, again for aesthetic reasons.)


I guess because arrays use pointer arithmetic to refer to some value. Basically arrays have contiguous memory and if you want to refer to 5th element (a[4]) then a + 4 * size of int is performed

Say if you start with 1 then to refer to 5th element you will have to do something like a + (5-1) * size of int