In 0-based indexing system, do people call the element at index 0 the "first" or the "zeroth" element?
In Java/C++, for example, do you casually say that 'a'
is the first character of "abc"
, or the zeroth?
Do people say both and it's always going to be ambiguous, or is there an actual convention?
A quote from wikipedia on Zeroth article:
In computer science, array references also often start at
0
, so computer programmers might use zeroth in situations where others 开发者_高级运维might use first, and so forth.
This would seem support the hypothesis that it's always going to be ambiguous.
Thanks to Alexandros Gezerlis (see his answer below) for finding this quote, from How to Think Like a Computer Scientist: Learning with Python by Allen B. Downey, Jeffrey Elkner and Chris Meyers, chapter 7:
The first letter of
"banana"
is nota
. Unless you are a computer scientist. For perverse reasons, computer scientists always start counting from zero. The 0th letter (zero-eth) of"banana"
isb
. The 1th letter (one-eth) isa
, and the 2th (two-eth) letter isn
.
This seems to suggest that we as computer scientists should reject the natural semantics of "first", "second", etc when dealing with 0-based indexing systems.
This quote suggests that perhaps there ARE official rulings for certain languages, so I've made this question [language-agnostic]
.
It is the first character or element in the array, but it is at index zero.
The term "first" has nothing to do with the absolute index of the array, but simply it's relative position as the lowest indexed element. Turbo Pascal, for example, allows arbitrary indexes in arrays (say from 5 to 15). The element located at array[5] would still be referred to as the first element.
To quote from this wikipedia article:
While the term "zeroth" is not itself ambiguous, it creates ambiguity for all subsequent elements of the sequence when lacking context, since they are called "first", "second", etc. in conflict with the normal everyday meanings of those words.
So I would say "first".
Probably subjective but I call it the first element or element zero. It is the first and, Isaac Asimov's laws of robotics aside, I'm not even confident that zeroth is a real word :-)
By definition, anything preceding the first becomes the first, and pushes everything else out by one.
Definitely first, never heard zeroth until today!
I would agree with most answers here, which say first character which is at zero index, but just for the record, the following is from Allen Downey's book "Python for Software Design":
So b is the 0th letter (“zero-eth”) of 'banana', a is the 1th letter (“one-eth”), and n is the 2th (“two-eth”) letter.
Thus, he removes the ambiguity by either using:
a) a number and then "th", or b) a word and then "-eth".
The C and C++ standards say "initial element" and "first element", meaning the same thing. If I remember to be unambiguous, I say "initial", "zeroth", or "first counting from zero". But normally I say "first". That banana stuff is either a humorous exaggeration or a bit bonkers (I suspect the former - it's just a way to explain 0-indexing). I don't think I know anyone who would actually say "first" to mean "index 1 of a 0-indexed array" unless they had first said "zeroth" in the same paragraph in order to make it clear what they mean.
It depends of whether or not you are a fan of Isaac Asimov's robot series.
精彩评论