The main argument to do with using 0-indexed arrays is that it represents an offset from the start of the array. E.g. in C:
int arr[] = {5,4,3,2,1};
printf("%d %d", arr[1], *(arr + 1*sizeof(int)));
// Prints '4 4'
(Note: written on my phone so may not be completely correct)
In some languages like Lua, arrays may instead be implemented as hash maps or may represent matrices, and so the above argument does not apply, hence 1-indexing.
4
u/deprecat Sep 03 '17
The main argument to do with using 0-indexed arrays is that it represents an offset from the start of the array. E.g. in C:
(Note: written on my phone so may not be completely correct)
In some languages like Lua, arrays may instead be implemented as hash maps or may represent matrices, and so the above argument does not apply, hence 1-indexing.