Sunday, December 25, 2016

What is the best code troll you've ever seen?

Hehe, that reminds me of the time I wrote:

#define for for(int z=0;z<2;++z)for


in a major header and pissed off my entire team ;)

-------------------------
EDIT: Some non-programmers have asked for an explanation:

The "#define A B" preprocessor directive means "replace all instances of 'A' with 'B'"

So in this example, the first "for" is what should be replaced, and the rest is what it should be replaced with.

So, if someone writes their own for loop:

for(int i=0;i<10;++i){cout<<i;}

The output of this would normally be: 0123456789

But it will be invisibly transformed into a nested loop, which will run their loop twice:

for(int z=0;z<2;++z)for(int i=0;i<10;++i){cout<<i;}

So the output of this would be: 01234567890123456789

And will leave them scratching their heads. Mwuhahaha!!!


Read other answers by Dale Thomas on Quora: Read more answers on Quora.

from Quora http://ift.tt/2hWljmW

No comments:

Post a Comment