LogiQuest
Back to Objects and Classes
3

What will be the output of the program?

#include <iostream>
using namespace std;
class A {
public:
    int x = 1;
    A& add(int n) { x += n; return *this; }
};
int main() {
    A a;
    a.add(2).add(3);
    cout << a.x << endl;
    return 0;
}
Medium

Discussion (0)

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

Log in to join the discussion.