What does this program print? struct A { A() { cout << 1; } ~A() { cout << 2; } }; int main() { A a; }.
-
A
12
Correct answer
-
B
21
-
C
1
-
D
2
12 views
Explanation
The constructor prints first and the destructor prints when a leaves scope, producing 12.
Reference
Asked in: NTS, PPSC IT, Campus Interviews
Doubts & discussion
Not sure why the answer is A? Ask here and get an explanation.
Ask a doubt about this MCQ