Why index start with 0 but not with 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why index start with 0 but not with 1

13th Feb 2017, 6:48 PM
Suresh Erragana
Suresh Erragana - avatar
3 Answers
+ 5
computers work in binary code, and binary code starts from 0, so in programming there are lots of thing which start from 0 however Mario's answer is better ^-^
13th Feb 2017, 8:56 PM
Kamil
Kamil - avatar
+ 3
very detailed answer: http://stackoverflow.com/questions/7320686/why-does-the-indexing-start-with-zero-in-c (the long one, not the first answer)
13th Feb 2017, 7:24 PM
Mario L.
Mario L. - avatar
+ 2
It's a logical, mathematical reason: imagine you count floor in a building, and each item array is a stage... first element is on ground floor, level 0, second on frst floor, and so on. Now, you want to convert the level into the height to where each item is stored ( the memory address ): you know that the height of each floor ( the space required by a type of data ) is H... considering our numeration starting at zero, we can tell: height of item at level N is equal to height H times by level N ^^
14th Feb 2017, 2:10 AM
visph
visph - avatar