0

int main(){ float a = 0.7; if(0.7>a) printf("hi"); else printf("bye "); } output: hi <---can anyone explain the above code.

30th May 2019, 3:08 AM
Bala Kumaran
Bala Kumaran - avatar
4 Respostas
30th May 2019, 3:39 AM
Bilbo Baggins
Bilbo Baggins - avatar
+ 1
it's because you're comparing a double with a float. number literals are automatically treated as doubles. a double has more memory allocated than float. if you do float b=0.7 and then compare it with a, you would get the desired results.
30th May 2019, 3:40 AM
Farry
Farry - avatar
0
when a=0.7, the output is hi. but here the condition is 0.7>a. then how it is print hi as a output.
30th May 2019, 3:13 AM
Bala Kumaran
Bala Kumaran - avatar
- 1
You're checking if 0.7 is greater than a // 0.7>a // 0.7>0.7 Which is false or not true as they have same value. So the output is hi
30th May 2019, 4:32 AM
Anurag
Anurag - avatar