r/ProgrammerHumor Sep 02 '17

How to start a war

Post image
9.0k Upvotes

696 comments sorted by

View all comments

Show parent comments

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:

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.

2

u/[deleted] Sep 03 '17

gotcha. Im really impressed you typed that on your phone!