0

Explain the output please.

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

1st Feb 2019, 5:23 PM
Rakesh Singh
Rakesh Singh - avatar
5 Réponses
0
But if you compile this code the output is hi.... Seb TheS
1st Feb 2019, 8:59 PM
Rakesh Singh
Rakesh Singh - avatar
+ 3
Because the expression 0.7>a is false, if statements were ignored, else statements were executed instead, printed "hello"
1st Feb 2019, 7:43 PM
Seb TheS
Seb TheS - avatar
+ 2
Well I have a hypothesis that decimal numbers are set to double floating point numbers as default. Because different datatypes are compared, C may compare them by their memory instead. Doubles require 2*more memory that floats.
1st Feb 2019, 9:04 PM
Seb TheS
Seb TheS - avatar
+ 2
The hypothesis worked only, when the values in the example were equal.
1st Feb 2019, 9:15 PM
Seb TheS
Seb TheS - avatar
0
Yes, Now I understand 😊😊 Thank you Seb TheS
2nd Feb 2019, 5:36 AM
Rakesh Singh
Rakesh Singh - avatar