Question OOP-CTOR-0041
MediumWhat is the output of this code?
#include <iostream>
using namespace std;
class T {
int id;
public:
T(int i) : id(i) { cout << "C" << id << " "; }
~T() { cout << "D" << id << " "; }
};
int main() {
T a(1);
{
T b(2);
}
T c(3);
}
- A.
C1 C2 D2 C3 D3 D1
- B.
C1 C2 C3 D3 D2 D1
- C.
Sign up free to see the answer and a step-by-step explanation.