Possible Duplicate:
Floating point comparison
#include<stdio.h>
#include<conio.h>
int main()
{
float i=0.7;
clrscr();
if(i < 0.7)
printf("If Block");
else
printf("Else Block");
getch();
return 0;
}
I dont understand whay the output will be “If block”…..please help why the if part is executed?
Actually
iis0.69999999998in it’s floating representation.When you assign
i=0.7in memory 0.7 cannot be represented indouble precisionas you would have thought.So the comparison between
floatanddoubleleads to type promotion and in that caseiis less than0.7which is double.