I have a question on C/C++ arrays.
Why does the index of the arrays start from '0' not from '1'?
Is there any mathematical reason for that?
I have a question on C/C++ arrays.
Why does the index of the arrays start from '0' not from '1'?
Is there any mathematical reason for that?
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.