in c, the floating point number shouldn't used in codition statement. the compiler take like below for given code, if(0.699<0.7) so , the output will be "yes"
in c the floating point number shouldn't used in codition statement. the compiler take like below for given code if(0.699<0.7) so the output will be "yes"
All floating point values are stored as double. So in the given program the value of variable "a" is interpreted as 0.69999999 thus "double" is truncated to "float".
Even Some compillers will generate a warning as follows :
initializing' : truncation from 'double' to 'float'
This is one possible reason for the wrong output.
NOTE : Also during condition checking there will be implicit type conversion among the different data types and their values thus leading to unexpected results.So one should be very careful when checking for variables of different data types.
The if condition in the above can be modified as
if(a < (float)0.7) to get the correct output(expected output).
When a 0.7 internally compiler treats 0.7 as double. Now a is a float and float is always small then double so the if condition is true and answer will be