Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It also makes modulo math easier. Starting at the first element in an array and jumping to every 8th element thereafter gives you indices of 1, 9, 17, 25, etc for 1-indexed arrays. It's not immediately, intuitively, obviously clear that the index is 8n+1. However, 0-index arrays would be 0, 8, 16, 24, which is very clearly 8n.

There is no argument for 1-indexed arrays other than, "so-and-so can't be arsed to learn 0-indexed."



This makes indexing 2d arrays as 1d arrays a lot easier. With 0-based, index = x + y * width, while 1-based, index = ((x-1) + (y-1) * width) + 1




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: