LogiQuest
Back to Constructors and Destructors
2

What will be the output of the program?

#include <iostream>
using namespace std;
class A {
    int id;
public:
    A(int i) : id(i) { cout << "C" << id; }
    ~A() { cout << "D" << id; }
};
int main() {
    A a(1);
    A b(2);
    return 0;
}
Medium

Discussion (0)

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

Log in to join the discussion.