Indexes start from zero because they’re memory offsets, but array[0]
is still the first element because it’s an ordinal number, not an offset. It’s literally counting each element of the array. It lines up with the cardinality—you wouldn’t say ['A', 'B', 'C']
has two elements, despite array[2]
being the last element.
Yeah, fair enough. To my mind I guess I don’t think of array indexes as an example of actual zero based numbering, simply a quirk of how pointers work. I don’t see why one starting from zero has anything to do with the other starting from zero. They’re separate things in my head. Interestingly, the article you linked does mention this argument:
That said, I suppose I still use normal one-based numbering because that’s how I’m used to everything else working.