LogiQuest
Back to Operator Overloading
11

What will be the output of the program?

#include <iostream>
using namespace std;
struct C {
    int n;
    C &operator+=(int k) { n += k; return *this; }
};
int main() {
    C c{1};
    (c += 2) += 3;
    cout << c.n << endl;
    return 0;
}
Medium

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.