+ 6

Why Index starts from 0, I mean, what's the logic behind it?

Hello. Why Index starts from 0, I mean, what's the logic behind it? Is there any logic or it's just for fun! Thanks all. I'll be appreciated.

5th Jun 2018, 11:32 AM
xXx
xXx - avatar
8 Respostas
+ 10
I think when index starts from 0, it can save 1 bit memory
5th Jun 2018, 1:59 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 7
Raj Chhatrala You're right and I believe Muhd Khairul Amirin Bin Yaacob means we would store 1 number less within the same storage or waste it if we start counting from 1. 😉
5th Jun 2018, 2:25 PM
Zephyr Koo
Zephyr Koo - avatar
+ 6
You may think of the first element to be the anchor at position 0 and therefore the next element is *1* offset away and so on. 😉
5th Jun 2018, 2:04 PM
Zephyr Koo
Zephyr Koo - avatar
+ 5
Consider array below [a,b,c,d,e] index 'a' of is 0 index 'b' of is 1 index 'c' of is 2 so index 'e' of is -1 I think thats why indexes start with 0
5th Jun 2018, 11:36 AM
Scorpia Rising🎩
Scorpia Rising🎩 - avatar
+ 5
Ahhhhh, sorry Muhd Khairul Amirin Bin Yaacob from my way of thinking, it doesn't matter that index start with 0 or 1 because number of elements to be stored will remain same. for example int a[5] will use 20 bytes in anyways, with 0 index or with 1 index. 🤔 ("I am not trying to prove you wrong. 😂")
5th Jun 2018, 2:07 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 3
Thomas Groenewald. Thank you for great explanation.
18th Jul 2018, 11:11 AM
xXx
xXx - avatar
+ 2
could be because we use base 10 which is "0, 1, 2, 3, 4, 5, 6, 7, 8, 9"... not " 1, 2, 3... ...8, 9, 10"... 10 isnt an extra number because it consists of pre-existant numbers (1 and 0), so 0 is our first number in our base 10 number sequence (for those who dont know what base 10 means, basically if you had base 5 u wont have the numbers 5 and up, base 5 would be "0, 1, 2, 3, 4'... and base 12 would be 0, 1, 2, 3... ...8, 9, 10, A, B"
18th Jul 2018, 10:52 AM
Thomas Groenewald
Thomas Groenewald - avatar