16 ответов
+ 9
Most of the languages starts the index at zero.
Please use the search bar next time to avoid duplicates.
https://www.sololearn.com/discuss/1005710/?ref=app
https://www.sololearn.com/discuss/521959/?ref=app
https://www.sololearn.com/discuss/379907/?ref=app
https://www.sololearn.com/discuss/785845/?ref=app
https://www.sololearn.com/discuss/139443/?ref=app
https://www.sololearn.com/discuss/91092/?ref=app
https://www.sololearn.com/discuss/1663141/?ref=app
+ 4
I had this question some time back.
Now consider a programming language like C or C++ which closely work with memory.
So whenever you pass an array as an argument, you only use the array name because it holds the memory address of the first element in the array.
Now if I want to access the first element in the array then I cannot write *(array+1) because then it would give me the value of 2nd element in the array because the 'array' itself holds the 1st element address. So you have to write *(array+0) to get the first element.
Hope it is clear now.
+ 3
You can also look here:
https://en.m.wikipedia.org/wiki/Zero-based_numbering
And here is a list with programming languages. As you can see not all are zero-based:
https://en.m.wikipedia.org/wiki/Comparison_of_programming_languages_(array)
+ 3
My personal imagination:
Every item of an array is not a point, but rather a 'width'. You can specify that: Like '8 bytes' or something.
So every item (whatever the specific 'width') has a beginning and an end.
I imagine a centimeter ruler. The first cm begins at zero, although it's the first. So if you want to find the beginning of the first cm/data item, you'd go to the zero.
Or take time on a clock: First hour begins at 0, second at 1. When we say 02:05, we're already in the third hour.
So it's also a bit of a convention (Python does it because the whole C clan does it), but you can find examples in real life.
+ 2
Are you asking for 'philosophical' reasons, like understanding the deeper reasoning, or are you having trouble practically dealing with it?
+ 2
Coder's Crux not all languages have array indices starting from 0. Some start them with 1.
+ 2
It was the choice of programmer who programmed python. , if you wish to start with 1,2,19 or other number get start to devlop another language.
+ 1
Thanks Coder's Crux I did use the search bar, but the top results wasn't what I was looking for
+ 1
Joseph Ojo
Can you explain which search was not helpful? Your own search or my search or both?