Some beginner programmers might struggle understanding why most languages have arrays that “start at 0”. I want to offer a short explanation that will hopefully help make sense of it.
“That’s not how we count things”
Well actually it is… sort of. But talking about “counting” and indices is really just mixing things up. An index is not an amount, it’s a position. Let’s look at a real world example of something that starts at 0: the (christian) calendar.
What year is it ?
I’m writing this in 2026, which happens to be during the 21st century. Do you see it yet ?
Why isn’t the year 2000 the start of the 20th century ? After all it starts with the number 20 not 21. To find out, we’ll go back in time to ask a simple question: what year marks the beginning of the 1st century of our era ? If the year 100 came to your mind, then what century starts at year 0 ? to what century belongs year 50 ?
“0th” isn’t a thing right ? How could anything be the zero-th element of a list ? If the 1st century starts at year 0, then year 100 starts the 2nd century, 200 the 3rd and so on. If we unroll our calendar:
And if we place the centuries into an array:
Without the trailing zeros:
That’s pretty much it. An index is not an amount or a counter, it’s a position, and the first element of an array is at index zero. If it sounds strange that a number can be a position you can look at it that way:
In a 2d space, made of 2 axis x and y, the origin is at (0,0). In a 1 dimensional space, the origin is (0). In the context of my calendar example: time is (generally) considered as one dimensional. In the context of arrays, dimensions apply directly:
[0] //-> first element of a 1d array
[0][0] //-> first element of a 2d array
Hope it helps. feedback welcome
Thank you for reading.<3
13/05/26 Etienne