+ 1
Why array index always starts from 0
3 Respuestas
+ 24
In most programming language, the name of any array is a pointer, which is nothing but a reference to a memory location, and so the expression array[n] points to a memory location which is n-elements away from the first element. This means that the index is used as an offset. The first element of the array is exactly contained in the memory location that array points to (0 elements away), so it should always be referred as array[0].
a[i] can also be read as value at [a+i] which is denoted as *(a+i) , so it always starts at zero.
0
In computer language, the bits or bytes starts from 0 only.. if u take hexadecimal it have 0 to f and so on... likewise in array, the index starts from 0.
- 2
that is actually how computers count dude. And it makes sense because u cant have 1 or 10 or 100 if 0 doesn't exist.