LogiQuest
Back to Operator Overloading
4

What will be the output of the program?

#include <iostream>
using namespace std;
struct C {
    int n = 0;
    C& operator++() { ++n; return *this; }
    C operator++(int) { C t = *this; ++n; return t; }
};
int main() {
    C c;
    C a = c++;
    ++c;
    cout << a.n << " " << c.n << endl;
    return 0;
}
Hard

Discussion (0)

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

Log in to join the discussion.