+ 6

It showing output hi. How's it?

float a = 0.7; if(0.7 > a) printf("Hi\n"); else printf("Hello\n");

1st Jun 2019, 5:06 AM
Shubham Tandale
Shubham Tandale - avatar
3 Antworten
+ 7
Because you need to define 0.7 in your if statement as a float (write 0.7f instead of 0.7) If you don't include the "f" the compiler sees the value as a double instead of a float. Double values have more precision than float values and 0.7 as a double will be greater then as a float.
2nd Jun 2019, 8:53 PM
haydenki
haydenki - avatar
+ 5
In smaller programs where memory is not much of a concern, perhaps it's better to use doubles rather than floats for reasons such as this?
2nd Jun 2019, 10:36 PM
Sonic
Sonic - avatar
1st Jun 2019, 5:12 AM
Théophile
Théophile - avatar