3 ms·
I think that zero indexed is generally better, including that it involves adding the index number to the base address, and other properties that can be helpful.
by zzo38computer 4y ago
I think that zero indexed is generally better, including that it involves adding the index number to the base address, and other properties that can be helpful.
However, it can also be useful for many purposes to allow arbitrary ranges, so a programming language probably should allow that; if the index of the first element is not zero, then the base address will not be the address of the first element (if the first element index is positive, then the base address may actually point into a different array, or a different variable). Then, if you have the base address and add the index, you will have the proper address of that element, whether or not the first index number is zero.
Zero is not always the most useful starting index; sometimes other numbers (which may be positive or negative) are useful. But, I think in general, zero is better.