What is the logic behind programming languages 0-indexing?

587 views

As someone who primarily uses R, I don’t understand why Python indexes lists starting from 0. I’m very slow at simple mental calculations and doing something like subsetting an array in Python often takes me several extra seconds.

I think I read that it has something to do with memory, but thats so much less of a consideration for people who only use high level languages.

In: Technology

9 Answers

Anonymous 0 Comments

Because that’s how address registers in the hardware work. If a “pointer” in a language is the address of the start of an array, the first element is at that address. The hardware’s “load indexed” instruction takes an address register for the base and another register as the index. The address+0 location contains the first element in the array.

You are viewing 1 out of 9 answers, click here to view all answers.