if(printf("Hello world")){}
The output for above code is
Hello world
My friend told me that the function printf returns the length of characters which is non zero here, so the condition is true.
But I can't understand why it executes that printf statement. Shouldn't printf be executed only when it is inside { }?
The expression within if(expression) is always evaluated, and in your case that's a call to printf.
The value of this expression is used to determine if the body (blank in your case) of the if is run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With