Consider below two snippets
int main() {
float a = 1.5;
if(a == 1.5) cout << "Yes\n";
else cout << "No\n";
return 0;
}
Output : Yes.
int main() {
float a = 0.7;
if(a == 0.7) cout << "Yes\n";
else cout << "No\n";
return 0;
}
Output: No.
Why is the output different in the two case? I know that by default floating point constants are double so comparison in second snippet between a float ( a ) and double ( 0.7 ) becomes false and output is No. But I couldn't figure out so as why the output is Yes in case of first snippet. Please help!