+ 2

Why this piece of code print c++ when condition is not true

Why this piece of code print c++ #include<stdio.h> Int main () Float a=0.7; If(a>0.7) { Printf("C"); Printf("++"); } Return 0; }

1st Feb 2020, 4:54 PM
tushar sahni
tushar sahni - avatar
3 Respuestas
+ 2
Double type is the default type for decimal values. In your code 0.7 is double type value. So both, a, 0.7 are converted equal type, obviously to higher double type, and when converted, because convertion, that a contains slightly higher value than double 0.7. 0.7 odd value, this is not same happens if is even, ex :0.8. So double type values is obviously greater than float value in the internals.. And also they are not same.. Check by this.. if(a==0.7) printf("same double"); if(a==0.7f) printf("same float");
1st Feb 2020, 8:52 PM
Jayakrishna 🇮🇳
0
Your float a is not bigger than 0.7. They're equal. Your compare holds that printing will happen, if a is bigger than 0.7 And I think you should type in lowercase like int, float, if etc
1st Feb 2020, 5:11 PM
Veli-Matti
0
https://code.sololearn.com/cKWndM3klL01/?ref=app See this code it gives no output.
28th Jun 2020, 9:01 PM
tom
tom - avatar