Zero-based numbering: Difference between revisions

Content deleted Content added
revert replacement of text by unsourced personal opinion
Add missing comma
Line 38:
Hence, the efficiency benefit at run time of zero-based indexing is not inherent, but is an artifact of the decision to represent an array with the address of its first element rather than the address of the "imaginary" element preceding the array. However, the address of that "imaginary" element located immediately before the first actual element of the array could very well be the address of some other item in memory not related to the array.
 
A third property is that a range is more elegantly expressed as the half-open [[Interval (mathematics)|interval]], [0,''n''), as opposed to the closed interval, [1,''n'']. Empty ranges, which often occur in algorithms, are tricky to express with a closed interval without resorting to obtuse conventions like [1,0]. This half-open convention may avoid [[off-by-one error]]s or [[fencepost error]]s. On the other hand, often the repeat count ''n'' is calculated in advance, making the use of counting from 0 to ''n''−1 (inclusive) less intuitive.
 
This situation can lead to some confusion in terminology. In a zero-based indexing scheme, the first element is "element number zero"; likewise, the twelfth element is "element number eleven". Therefore, an analogy from the ordinal numbers to the quantity of objects numbered appears; the highest index of ''n'' objects will be {{nowrap|''n'' − 1}} and referred to the ''n''th element. For this reason, the first element is often referred to as the ''[[zeroth]]'' element to avoid confusion.