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

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

Say Thanks
Respond

1 Response
Add your response

6418
1cecef5162037105dc0e5a0a14ab4dcc

Haha, very cool indeed.

over 1 year ago ·