experiments.
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 int 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 ;-)
1) {return 0;} if (0
ok, let's make it harder, can this be done by invoking a single function?
1/0
if(main()){} // stack overflow not considered
freopen( "/dev/null", "w", stdout )
#includeYou could close stdout.if(close(1) == 0){ printf("foo");}
If we consider to build this code with a C++11, we can do this:#include int main() { if (auto printf = [=](const char*){}) { printf("foo"); } else { printf("bar"); } return 0;}
if ( void (*printf) (const char*) = nullptr)you can use also lambda
[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;
}
if ( void (*printf) (const char*) = nullptr)
ReplyDeleteyou can use also lambda