+ 1
#include <stdio.h> int main() { float a=0.7; if(0.7>a) printf("hi"); else printf("hello"); }
Why the output is hi
3 Answers
+ 9
Rohit Ahuja
It's because aĀ isĀ 0.69999999998Ā in it's floating representation.
And normal 0.7 is an double precision value, So the comparison betweenĀ floatĀ andĀ doubleĀ leads to type promotion and in that caseĀ aĀ is less thanĀ 0.7Ā which is double. So the output will be printed as hi
this thread will give you some detailed answer about the precision value types
https://www.sololearn.com/Discuss/796595/?ref=app
0
Thanks GAWEN
0
How can we know that a=0.69999999998 ???