+ 1

#include <stdio.h> int main() { float a=0.7; if(0.7>a) printf("hi"); else printf("hello"); }

Why the output is hi

24th Jul 2019, 12:53 PM
Rohit Ahuja
Rohit Ahuja - avatar
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
24th Jul 2019, 1:04 PM
GAWEN STEASY
GAWEN STEASY - avatar
0
Thanks GAWEN
24th Jul 2019, 1:08 PM
Rohit Ahuja
Rohit Ahuja - avatar
0
How can we know that a=0.69999999998 ???
25th Dec 2022, 6:46 AM
BOTU HARSHA VARDHAN
BOTU HARSHA VARDHAN - avatar