Would it be possible to print Hello
twice using single condition
?
if \"condition\"
printf (\"Hello\");
else
printf(\"World\");
Without knowing the return value of printf
off the top of your head:
if (printf("Hello") && 0)
printf("Hello");
else
printf("World");
Abuse of preprocessing - with cleanup at least.
#define else
if(1)
{
printf("hello");
}
else
{
printf("world");
}
#undef else
if ( printf("Hello")==0)
see [http://www.coders2020.com/what-does-printf-return]
(matt corrected my =, thanks, C is far away)
#include<stdio.h>
int main()
{
if(! printf("Hello"))
printf ("Hello");
else
printf ("World");
return 0;
}
Because Printf returns the number of character it has printed successfully.
Just put the code before or after the if..else block.
Alternatively, if you have an "if, else if, else" block where you want to execute code in some (but not all) branches, just put it in a separate function and call that function within each block.
if ( printf("Hello") == 0 )
printf ("Hello");
else
printf ("World");
:-)