Determine the if condition to print specific output

What should be the if condition in below code snippet, so that output would be “Hello World”.


if “condition”
    printf (“Hello”);
else
    printf(“World”);


Method 1: Using printf()

 

 
We can also use comma operator instead of depending upon the return value of printf in order to know what the conditional clause does.

 

Method 2: Recursive main()

 

 

Note that we can use write custom function instead of calling main() recursively –
 

 

References:
http://stackoverflow.com/questions/33199/whats-the-condition-in-c-interview-test
 

Thanks for reading.




Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂