-4

v it's an array of ints and a it's an int:

#include <iostream>
using namespace std;
int main() {
int v[10], a;
cout << v[a] << endl;
cout << a[v] << endl;
return 0;
}

returns the same value: 0 0

Why is that ?

1 Answers1

6

Because the indexer syntax means "the value in the address denoted by the beginning of the array plus an offset". Or, to put it another way:

v[a] == *(v + a) == *(a + v) == a[v]
Theodoros Chatzigiannakis
  • 28,773
  • 8
  • 68
  • 104