Operator Functions

Q.

1.
    #include 
2.
    using namespace std;
3.
    class Integer 
4.
    {
5.
        int i;
.
        public:
7.
        Integer(int ii) : i(ii) {}
8.
        const Integer
9.
        operator+(const Integer& rv) const 
10.
        {
11.
            cout << "operator+" << endl;
12.
            return Integer(i + rv.i);
13.
        }
14.
        Integer&
15.
        operator+=(const Integer& rv) 
16.
        {
17.
            cout << "operator+=" << endl;
18.
            i += rv.i;
19.
            return *this;
20.
        }
21.
    };
22.
    int main() 
23.
    {
24.
        int i = 1, j = 2, k = 3;
25.
        k += i + j;
26.
        Integer ii(1), jj(2), kk(3);
27.
        kk += ii + jj;
28.
    }

a) operator+

operator+=

b) operator+=

operator+

c) operator+

operator+

d) None of the mentioned

Explanation :

Answer: (a)
Explanation:We are using two operator functions and executing them and result is printed according to the order.
Output:
$ g++ oper2.cpp
$ a.out
operator+
operator+=