+ 3

Please explain this code ?

float a=0.7; if(0.7>a) printf("Hi\n"); else printf ("Hello\n");

27th Jul 2019, 7:28 AM
Pon Balaji
Pon Balaji - avatar
4 Answers
+ 12
In if statement you are comparing a double precision floating point to a single precision floating point. 0.7 (double)approximate value is greater than 0.7f For more explanation you can refer : https://www.quora.com/include-stdio-h-void-main-float-a-0-7-if-a-0-7-printf-1-else-printf-2-The-output-of-the-above-program-is-1-How
27th Jul 2019, 7:40 AM
Nova
Nova - avatar
+ 3
Thanks for your answers
27th Jul 2019, 7:47 AM
Pon Balaji
Pon Balaji - avatar
+ 2
What part don't you understand? It's basic logic... if this condition is true, do this, if not, do that
27th Jul 2019, 7:37 AM
Frenchtoast
Frenchtoast - avatar