Vidyalelo
C++ Programming · Q40

Classes and Objects in C++

Programming · C++ Programming · question 40

Q40

What will be the output of the following C++ code? #include 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+=
Answer
B.
operator+=
operator+
C.
operator+
operator+
D.
operator+
operator=

Answer: Option A

Solution

Answer: Option A
No explanation is given for this question Let's Discuss on Board