Home » C++ Programming » Operators » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Example
    {
    public:
    Example(int k) : num_k(k) { }
    public:
    int operator()(int k = 0) const
    {
    return num_k + k;
    }
    operator int () const
    {
    return num_k;
    }
    private:
    int num_k;
    friend int g(const Example&);
    };
    int fun(char Z)
    {
    return Z;
    }
    int main()
    {
    Example fun(6);
    cout << fun(5);
    return 0;
    }
    1. 6
    2. 5
    3. 11
    4. Compilation Error
    5. None of these
Correct Option: C

In this program, we are adding its value with it itself, So only we got the output as 11.



Your comments will be displayed only after manual approval.