r/computerscience • • Apr 02 '25

Counting from 0

When did this become a thing?

Just curious because, surprisingly, it's apparently still up for debate

0 Upvotes

70 comments sorted by

View all comments

Show parent comment

2

u/SlippySausageSlapper Apr 02 '25

Zero is not a positive integer. Zero is zero.

The reason arrays are zero indexed is because in lower-level languages, the index internally represents an offset multiplier for pointers to members of the underlying data structure in memory. The first element has an offset of zero, all other elements have an offset of (index * multiplier), where the multiplier is the size of the individual array elements in memory. Higher-level languages later came along and emulated this behavior.