CJCoding With Joseph
15per day
← Back to Question List
C++ Code Walkthrough #3

Constructor and Destructor Order

hardClasses

📄 Code

Read carefully — what does this print?
1#include <iostream>
2using namespace std;
3 
4class Box {
5public:
6 int id;
7 Box(int i) : id(i) {
8 cout << "Create " << id << endl;
9 }
10 ~Box() {
11 cout << "Destroy " << id << endl;
12 }
13};
14 
15int main() {
16 Box a(1);
17 Box b(2);
18 return 0;
19}

🎯 Your Answer