Last Updated: December 30, 2020
·
1.993K
· 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

Haha, very cool indeed.

over 1 year ago ·