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 ?
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 ?
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]