Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 not a. Unless you are a computer scientist. For perverse reasons, computer scientists always start counting from zero. The 0th letter (zero-eth) of "banana" is b. The 1th letter (one-eth) is a, and the 2th (two-eth) letter is n.

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].

like image 486
polygenelubricants Avatar asked Apr 08 '10 14:04

polygenelubricants


People also ask

Does an array index start at 1 or 0?

To fit this definition of arr[i], indexing of array starts from 0.

What does 0 indexed array mean?

Zero-based array indexing is a way of numbering the items in an array such that the first item of it has an index of 0, whereas a one-based array indexed array has its first item indexed as 1. Zero-based indexing is a very common way to number items in a sequence in today's modern mathematical notation.

When array indexes start with zero it is called zero?

This means that the index is used as an offset. The first element of the array is exactly contained in the memory location that array refers (0 elements away), so it should be denoted as array[0] . Most programming languages have been designed this way, so indexing from 0 is pretty much inherent to the language.

Why must we start the array index at 0 instead of 1?

In array, the index tells the distance from the starting element. So, the first element is at 0 distance from the starting element. So, that's why array start from 0.


1 Answers

It is the first character or element in the array, but it is at index zero.

like image 192
Jason Coco Avatar answered Oct 05 '22 18:10

Jason Coco