Since the array index starts from 0, a[i] can be implemented as *(a i).
If the array index starts from 1, then a[i] will be implemented as *(a i-1), which will consume more time during the compilation process, and the performance of the program will also be affected.
Therefore, it is better to index the array starting from 0.
Given a simple array program -
int main() { int array[5] = {7, 7, 7, 6, 6}; for (int i = 0; i < 5; i++) cout << *(array + i); return 0; }
7 7 7 6 6
The above is the detailed content of Why do C/C++ array indexes start from zero?. For more information, please follow other related articles on the PHP Chinese website!