News for hackers. Stuff that matters.
Re:Edsger Dijkstra's note on starting array indices at 0 (pd... by epenn on Tuesday June 21, 2011 @07:56PM (#2680927)
Maybe this is some of my love for C shining through, but I've always thought of an array index as denoting the distance from the array pointer to the current/desired position. Thus in an array of integers for example, array[0] represents what's in memory at the pointer itself. array[1] is then the value in memory at sizeof(int) * 1 away. array[2] is sizeof(int) * 2 away, and so on.

A good analogy to this way of thinking is a person's age. When a person is born, or in other words when a person is at the beginning of the array of years that he/she exists, the age index is 0. At the person's first birthday, the age index is 1. Then 2, 3, and so on.

I guess the tl;dr then is that I agree with Dijkstra that array indices should begin at zero.

There are no comments on this comment yet.