0

Float and double comparison (==). Here f is float and 1.25 is double how they can be equal?

int main() { float f = 1.30; int i=5; while(i--) { f = f - 0.01; } if(1.25 == f) printf("True "); else printf("False"); return 0; } Answers 1. Infinite Loop 2. No Output 3. False 4. True

24th Jun 2022, 4:45 PM
Akshay Bhujbal
2 Answers
+ 1
They don't equal. But there it is compared values not the types in c. In any calculation of instruction, the operands are first converted or upcasted to higher types , then calculation is evaluated. So both double type values are compared but may or may not equal, because of fraction part differences..
24th Jun 2022, 5:06 PM
Jayakrishna šŸ‡®šŸ‡³
0
The answer is True I don't know why. They should not be equal
28th Jun 2022, 2:41 PM
Akshay Bhujbal