-2

if(printf("Programmer Boy Amit"))

What will be the output?

pro

9/11/2019 7:29:27 AM

Amit Singh Raghuvanshi

7 Answers

New Answer

+3

Programmer Boy Amit

+3

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

+3

Run this code and see output

+3

Yes it's correct

+2

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.

+2

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/

+1

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).