Let's consider an analogy to grasp the essence of the question. In the context ofHuman counting floorsintuitively revolves around two different cases:
a) In some countries, like the US, floors are labeled as 'first floor,' 'second floor,' and so on. b) In other countries, such as the UK, counting begins from the 'Ground floor,' followed by 'first floor,' and so forth. The total element count in a list or a collection:
We do so by assigning '1' to the first element and counting upwards (Rarely, we may choose to assign '0' to the first element, as in the floor counting system in the UK where the first floor is called 'Ground floor'). Example: Counting the total apples in a bag by starting the count from 1.
The total distance traveled from the first position:
We do so by assigning a certain value to the starting position, and then adding the offset on it as we traverse a certain distance. Now, what value to assign to the starting position to simplify the calculation? As you might have probably guessed, assigning 0 to the starting position makes calculation much easier. Example: Measuring the distance means keeping the measuring tape such that the "zero" reading is at the starting position. This is what others have pointed out as well.
These methods parallel the debate over whether computers should count from 1 or 0. So, which counting method is better? InLet's get to the caseworld of computers, one method may prove slightly more advantageous than the other.
Human counting often revolves around the length of a list, assigning '1' to When we talk about the first element and counting upwards (Occasionallyof an array being called '0', we may choose to assign '0' toare not talking about the first element count, as seen inbut rather the floor counting systemposition in the UK). By doing soarray, it implies that '0' represents something beforejust like in the first element—an absence or nothingnesssecond case above. This observation aligns with the idea that, in a sense, humans also start counting from zeroIt's essential to recognize this distinction, as others have pointed out.
However, Computers are concernedour intuition might lead us to compare computer numbering with the positionsfirst case in the list, rather than the lengthhuman counting. So assigning '0' to the first value of the listarray simplifies indexing. It's so becauseThis means in a computer's memory, the position/addressaddress of the next value in the listelement can be determined withusing the help of an offset rule. In the following 2 cases, it's much easier
While compiler optimizations might have likely been implemented to calculateaccommodate this convention, the option 'a' (where counting beginsinfluence of languages like C, which starts indexing from 0) than the option 'b''0' (where counting beginsunlike FORTRAN that starts from 1'1'):
a) element(n) = address + n * size_of_the_element b) element(n) = address + (n-1) * size_of_the_element The design philosophy of computers predates the development of programming languages, has solidified this approach. Now that we know the philosophy behind why 0Just like there is the first numberno need to alter a computer, lets look intomeasuring tape where the casereading starts with 1 instead of programming languages0, even though human brain is already "optimized" (smart) to seecalculate the convenience in use cases:
a) Languages like FORTRAN and COBOL start counting from 1 b) Languages like C and Python start the count from 0. You are free to build your own language that startsdistance even if the indexingreading started from -1 all the way up, but it will probably add more to the confusion, and it probably won't be efficient1.