Home » C++ Programming » Operators » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    ostream & operator<<(ostream & k, int num)
    {
    return k;
    }
    int main()
    {
    cout << 10 << endl;
    cin.get();
    return 0;
    }
    1. 10
    2. Compilation Error
    3. Runtime Error
    4. Garbage Value
    5. None of these
Correct Option: B

In this program, there will arise an ambiguous overload for 10.
Compilation Error

In function 'int main()':
9:14: error: ambiguous overload for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream}' and 'int')
9:14: note: candidates are:
In file included from /usr/include/c++/4.9/iostream:39:0,



Your comments will be displayed only after manual approval.