+ 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.
8 Antworten
+ 10
I think when index starts from 0, it can save 1 bit memory
+ 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. 😉
+ 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. 😉
+ 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
+ 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. 😂")
+ 3
Thomas Groenewald. Thank you for great explanation.
+ 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"