{ int i; if(printf("0")) i=12; else i=13; printf("%d\n",i); return 0; } how the op is 012?? | SoloLearn: Learn to code for FREE!

+1

{ int i; if(printf("0")) i=12; else i=13; printf("%d\n",i); return 0; } how the op is 012??

I have not been able to understand the program.

2/5/2020 12:23:46 PM

Muskan Mishra

5 Answers

New Answer

+2

if(printf("0)) it just checks if the command printf is true which is tottally true and prints 0, then i=12. And finally it prints the i which is 12. Moreover if(printf("0") ) first checks the condition printf("0") which is true, meaning that printing a character 0 it's tottaly true. SO, 0 is printed and i=12 (because if condition is true), and then i which is 12 is printed. If you didnt understand tell me again to describe it better.

+1

printf function returns no. Charecter outputted.. printf("0") print 0, and the number of charecters outputted is 1, so if block executed... Print 12 So total output is 012

+1

https://code.sololearn.com/c3GfowiDl09K/?ref=app

+1

Well explained by Jayakrishna

0

Please put your code in Code Playground.