Image

Imageandrogy8 wrote in Imagecpp

array trick

A professor pointed out this neat array trick, and explained why it works, but I didn't fully understand his explanation

The trick is this: we all know we can access array elements using the arrayname[i] notation. But, much lesser known: it's also possible to access array elements using i[arrayname] notation.

For example:
int numbers[] = {10,20,30,40,50};
cout << 4[numbers] << " " << 3[numbers] << " " << 2[numbers]; // outputs "50 40 30"

Maybe someone can give me an explanation for why this trick works.