Which element of the array is the first?

Several times during the discussion about programming, I came to a misunderstanding caused by different ideas about how consecutive elements of an array based on zero relate to the use of ordinal numbers. There seem to be two opinions on this:

a[0] = "first"; a[1] = "second"; a[2] = "third; 

against

 a[0] = "zeroth"; a[1] = "first"; a[2] = "second"; 

I always preferred the former, knowing that the element "n-th" is an "element of index n-1". But I was surprised how many people found that they were intuitive and used the latest version.

Is one of these conventions more correct than the other? What should I use during discussion or documentation to avoid misunderstandings?

+6
language-agnostic arrays terminology conventions documentation
source share
5 answers

I think that the English meaning of the word " first " is unambiguous and refers to the original element of the sequence. β€œFirst” refers to the successor of the original element, this is simply wrong.

In cases where confusion may arise, I would say "third element with index 2".

+10
source share

The index of an element is highly dependent on the language (e.g. C: 0, Lua: 1), while the fifth element is the fifth element, it is just an index that may be different;)

I guess this way spreads the answer too ...

+5
source share

In some languages, such as Pascal, you can explicitly specify a range of indices. i.e.

 var stuff : array[-3..3] of integer; 

stuff[-3] is still the first element in the array, not the negative third.

+3
source share

Anyone who says β€œzero” should not really believe in indexing with a zero value.

+1
source share

The first is the one that is first taken from the stack.

0
source share

All Articles