What will be the output of the following C++ code?

#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

1 thought on “What will be the output of the following C++ code?”

  1. a
    Explanation: 0.5f results in 0.5 to be stored in floating point representations.
    Output:
    $ g++ float.cpp
    $ a.out
    equal

Leave a Comment