if(printf("Programmer Boy Amit"))

What will be the output?


9/11/2019 7:29:27 AM

Amit Singh Raghuvanshi

7 Answers

New Answer


Programmer Boy Amit


It's run without any error and print Programmer Boy Amit


Run this code and see output


Yes it's correct


There won't be output, printf is a void and the if statement need to get type boolean in the () so, because you didn't convert void to boolean the compilar will skip the if statement. Also, in java for example you will get error for this code.


Without a main function, and stdio header (optional), that line alone wouldn't output anything. Do you have any question? you can find out by testing code in Code Playground. Look at the "Return value" section of the reference here to understand why it can output something: http://www.cplusplus.com/reference/cstdio/printf/


In C and C++ this code will run, it's a common trick used to write programs that don't make use of semicolons. In C, printf() doesn't return void but the number of characters printed (which is most often discarded).