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
Written by Alexander Brevig
Related protips
1 Response
Haha, very cool indeed.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Cpp
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#