Why do list/array index starts from zero(0)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why do list/array index starts from zero(0)?

It's been a while now..! That I have been into programming , but I wasn't satisfied why list/array index starts from zero(0)?? While Lua starts from 1 ?

11th Apr 2021, 11:15 AM
Ankith M Kashyap
Ankith M Kashyap - avatar
6 Answers
+ 9
That's the way is it
11th Apr 2021, 11:17 AM
Apongpoh Gilbert
Apongpoh Gilbert - avatar
+ 2
11th Apr 2021, 11:31 AM
+ 2
We always assign a variable name to an array. So, that variable name references to a memory location where array elements are stored. The reason why index start from zero is that index is used as an offset. Suppose we have an array Arr = [1,2,3,4,5] Arr[0] actually means that first element is 0 element away from the memory location where the arr points as elements in an array are stored in a contiguous manner.
11th Apr 2021, 11:40 AM
CHANDAN ROY - avatar
+ 1
Everything thing begins with the value "0" and continues 1,2,....44,88,900.....etc So for an origin of anything it always stays "0" at the first place and then it develops bit by bit...
12th Apr 2021, 5:44 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
THIS IS MY GUESS, MAY NOT BE TRUE!!! > probably because of binary. Binary starts from 0, therefore counting array from 0 makes sense.
11th Apr 2021, 12:19 PM
KingDaniel2004 - avatar