Home » C++ Programming » Functions » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    class Example
    {
    int K;
    public:
    Example(int KK) : K(KK) {}
    const Example
    operator+(const Example& rv) const
    {
    cout << "operator++" << endl;
    return Example(K + rv.K);
    }
    Example&
    operator+=(const Example& rv)
    {
    cout << "operator++=" << endl;
    K += rv.K;
    return *this;
    }
    };
    int main()
    {
    int K = 2, L = 3, k = 4;
    k += K + L;
    Example KK(2), LL(3), MM(4);
    MM += KK + LL;
    }
    1. operator++
    2. operator++=
    3. operator++=
      operator++
    4. operator++
      operator++=
    5. None of these
Correct Option: C

We are using two operator functions and executing them and the result is printed according to the order.



Your comments will be displayed only after manual approval.