Why array index start with zero?why not from 1? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Why array index start with zero?why not from 1?

21st Nov 2017, 4:32 AM
Annewesha Roy
3 Answers
+ 7
Two reasons: 1) Starting from 0 saves 1 bit, meaning you can represent a larger number with less bits. 2) In C++ the arrays decay to pointers, which is just a pointer to the first element, which would be array + 0.
21st Nov 2017, 4:41 AM
aklex
aklex - avatar
+ 3
because it is the distance from first character. this helps computer to access these locations faster
21st Nov 2017, 1:10 PM
shobhit
shobhit - avatar
+ 3
Since it's C++ explicit, that's the format that is designed when the language was made. However, the starting index for an array variable being 0 or 1 is all dependent on the language. Here is a somewhat comprehensive list of languages and whether their array indeces start with [0] or [1]. Cheers. https://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28array%29#Array_system_cross-reference_list
22nd Nov 2017, 7:58 PM
Gennario Veltaine
Gennario Veltaine - avatar