adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    class sample
    {
        public:
        sample(int i) : m_i(i) { }
        public:
        int operator()(int i = 0) const 
        { 
            return m_i + i; 
        }
        operator int () const   
        { 
            return m_i; 
        }
        private:
        int m_i;
        friend int g(const sample&);
    };
    int f(char c)
    {
        return c;
    }
    int main()
    {
        sample f(2);
        cout << f(2);
        return 0;
    }

a.

3

b.

4

c.

5

d.

None of the mentioned

Answer: (b).4

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?