7 ms·
The “conceptual model of zero-based indexing” is: use the left fencepost as the index. This is consistent and easy to reason about. With one-based indexing, yo
by jacobolus 10y ago
The “conceptual model of zero-based indexing” is: use the left fencepost as the index. This is consistent and easy to reason about.
With one-based indexing, you can’t have arr[-1] as the last element (that would cause huge problems!). Languages with one-based indexing write something like arr[end] or arr[arr.length] to refer to the last element, with arr[end-1] or arr[arr.length-1] referring to the second-to-last element.
- int_19h 10y ago> With one-based indexing, you can’t have arr[-1] as the last element (that would cause huge problems!) Can you give some examples?