A friend of mine is learning C++ for the first time, and sent me this snippet:
int foo[] = { 3, 38, 38, 0, 19, 21, 3, 11, 19, 42 };
char bar[] = \" abcdefghijklm
In simplistic terms, the access of an array element in C (and in C++, when []
isn't overloaded) is as follows:
x[i] = *(x + i)
So, with this and a little bit of arithmetic...
foo[i][bar]
= (foo[i])[bar]
= (*(foo + i))[bar]
= *((*(foo + i)) + bar)
= *(bar + (*(foo + i)))
= bar[*(foo + i)]
= bar[foo[i]]
Don't use this "fact" though. As you've seen, it makes the code unreadable, and unreadable code is unmaintainable.