Possible Duplicate:
In C arrays why is this true? a[5] == 5[a]
I came about a piece of code that indexed into a string literal this way:
#include <iostream>
using namespace std;
int main()
{
cout << 1["52"] << endl;
cout << 0["52"] << endl;
}
I tried searching, but you can imagine the search terms bringing up unrelated topics. Can anyone explain how this works?
I realized it probably works with any pointer, so I tested this too:
#include <iostream>
using namespace std;
int main()
{
int a[2]; a[0] = 22; a[1] = 600;
cout << 1[a] << endl;
cout << 0[a] << endl;
}