Hi!
I teach C++ in schools in India. I don't have a good answer when
students ask me why arrays in C++ are numbered from 0 to n-1 for an
array of n elements. I hope somebody can tell me.
Thanks
Binoy
You have a stack of books on a table. The book at the bottom of the
pile is 0 books away from the table, its offset is zero. The next book
is a book away from the table, offset of 1.
Humans invented the decimal system because we have 10 fingers, label
each finger using a digit only. 10 is not a single digit.
The best answer is one involving range. If you know you have 10 books
then 10 is an upper limit:
const int n = 10;
books stack[n];
for( int i = 0; i < n; ++i ) { /*do stuff*/ }
Cover binary arithmetic, where a computer only has 0's and 1's. After
all, a 0 has just as much weight that a binary 1 does.
In the decimal system isn't the first decade 0 -> 9 ? How weird would
it be to suggest that the first decade is 1 -> 10 and the second 11 ->
20. If you would exclude 0 why not exclude 10 and 20 as well?
Those languages that do use index 1->10 in an array[10] allocate 11
elements and the first one is ignored / waisted.