+ 4
Why array index start with zero?why not from 1?
4 odpowiedzi
+ 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.
+ 3
because it is the distance from first character. this helps computer to access these locations faster
+ 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