Why the array starts from 0 ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why the array starts from 0 ?

please i am tired but not found any satusfied answer. help out me. !!

9th Mar 2017, 6:14 PM
Khateeb Bhutta
Khateeb Bhutta - avatar
4 Answers
+ 5
I guess because arr[i] means *(arr + sizeof(type) * index). So if you want to address the first element, i should be 0). Sorry if my notation is wrong or not understandable.
9th Mar 2017, 8:01 PM
Tamás Barta
Tamás Barta - avatar
+ 1
It's because it's technically an offset in an array, due to the use of a pointer in the program to call on indices. So the nth index is '0' away from itself, and the 2nd index is 1 away, and so on. Think of it less as a number, and more as an offset(or relationship) from the start(the zeroth position).
9th Mar 2017, 11:23 PM
Joel Hager
Joel Hager - avatar
0
That's just a rule like why 1=1... it needs to define rules to build something. Just take it like that, don't think about.
9th Mar 2017, 6:16 PM
Geoffrey L
Geoffrey L - avatar
0
but there's a logic behind it . i want that . :)
9th Mar 2017, 6:43 PM
Khateeb Bhutta
Khateeb Bhutta - avatar