7drjia
Last Updated: February 25, 2016
·
1.543K
· alexanderbrevig

C++ esoteric obfuscated array indexing: index[array]

DO NOT DO THIS

I just want to share this fun trick with you all.

#include <iostream>

int main() {
  int arr[] = { 1, 3, 5, 7, 9};
  std::cout << 2[arr] << std::endl;
  return 0;
}

That code will print 5!

It works because *(arr + 2) is the same as *(2 + arr).

Kind of cool right?

I'll repeat this again:

DO NOT DO THIS

1 Response
Add your response

6418

Haha, very cool indeed.

over 1 year ago ·