adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    class Integer 
    {
        int i;
        public:
        Integer(int ii) : i(ii) {}
        const Integer
        operator+(const Integer& rv) const 
        {
            cout << "operator+" << endl;
            return Integer(i + rv.i);
        }
        Integer&
        operator+=(const Integer& rv) 
        {
            cout << "operator+=" << endl;
            i += rv.i;
            return *this;
        }
    };
    int main() 
    {
        int i = 1, j = 2, k = 3;
        k += i + j;
        Integer ii(1), jj(2), kk(3);
        kk += ii + jj;
    }

a.

operator+ operator+=

b.

operator+= operator+

c.

operator+ operator+

d.

none of the mentioned

Answer: (a).operator+ operator+=

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?