+ 4
Why output is false?
INPUT: void main() { float a=0.7; if(a==0.7) printf("true"); else printf("false"); } OUTPUT : false
8 Respuestas
+ 6
I think...as he said
at if condition
should be if(a==0.7f)
Because 0.7 is double type in "if" while a is float
(0.7f is float)
+ 6
I'm not c++ expert though....
So
I can only say that
double is 8 bytes (64 bit)
float is 4 bytes (32 bit)
So yes as @sneeze said They both are different
+ 4
He talk about C So It's C
+ 1
Sneeze, it still show the output is false.
I want to know that why the output is false.
Generally its output come in "true". But why output is "false".
+ 1
Data type is different but those values are same, both (0.7).So why if condition doesn't satisfied.
+ 1
Default the compiler sees 0.7 as a double. Unless you tell the compiler it is a float.
0.7 double is not the same as 0.7 float because they are stored differently in memory and a double has more precission then a float.
0
https://code.sololearn.com/c53Xx6zPfk07
The float a=0.7; need a "f" to tell the compiler that 0.7 is a float.
I tested it in C#
float a=0.7f;
Hopes it works the same in the language you are working in.
0
in which language are you working