+ 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 odpowiedzi
+ 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