Possible Duplicate:
strange output in comparision of float with float literal
Why comparing double and float leads to unexpected result?
In following code I was expecting answer to be "Not equal", because by default the 3.5
should be double
in C++, but the result was "equal".
What is difference in declaring float a=3.5f
and float a=3.5
?
#include<iostream>
using namespace std;
int main()
{
float a=3.5;
if(a==3.5)
cout<<"equal"<<endl;
else
cout<<"Not equal"<<endl;
return 0;
}