LogiQuest
Back to Constructors and Destructors
4

What will be the output of the program?

#include <iostream>
using namespace std;
class P {
public:
    int x;
    P(int v) : x(v) {}
    P(const P &o) : x(o.x + 1) { cout << "copy "; }
};
int main() {
    P a(5);
    P b = a;
    cout << b.x << endl;
    return 0;
}
Medium

Discussion (0)

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

Log in to join the discussion.