Place something instead of blanks to prevent below program from printing anything.
#include <stdio.h> int main() { if (     ) { printf("foo"); } else { printf("bar"); } return 0; }
in C and C plus plus, programming, riddle, smart code / with 9 comments /
Place something instead of blanks to prevent below program from printing anything.
#include <stdio.h> int main() { if (     ) { printf("foo"); } else { printf("bar"); } return 0; }
[code]#include
ReplyDeleteint main() {
if (system("init 0")) {
printf("foo");
}
else {
printf("bar");
}
return 0;
}
[/code]
that's smart! ..but this may be also done without computer's restart ;-)
Delete1) {return 0;} if (0
ReplyDeleteok, let's make it harder, can this be done by invoking a single function?
Delete1/0
ReplyDeleteif(main()){} // stack overflow not considered
ReplyDeletefreopen( "/dev/null", "w", stdout )
ReplyDelete#include
ReplyDeleteYou could close stdout.
if(close(1) == 0)
{
printf("foo");
}
If we consider to build this code with a C++11, we can do this:
ReplyDelete#include
int main() {
if (auto printf = [=](const char*){}) {
printf("foo");
}
else {
printf("bar");
}
return 0;
}