#include <iostream> using namespace std; int main() { float f1 = 0.5; double f2 = 0.5; if (f1 == 0.5f) cout << "equal"; else cout << "not equal"; return 0; }
a) equal
b) not equal
c) compile time error
d) runtime error
#include <iostream> using namespace std; int main() { float f1 = 0.5; double f2 = 0.5; if (f1 == 0.5f) cout << "equal"; else cout << "not equal"; return 0; }
a) equal
b) not equal
c) compile time error
d) runtime error
You must be logged in to post a comment.
a
Explanation: 0.5f results in 0.5 to be stored in floating point representations.
Output:
$ g++ float.cpp
$ a.out
equal