1. Home
  2. Computer Science MCQs
  3. C++ and Object-Oriented Programming
  4. What does this program print? struct A { A() { cout

Added 30 Nov -0001

What does this program print? struct A { A() { cout << 1; } ~A() { cout << 2; } }; int main() { A a; }.

  1. 12 Correct answer
  2. 21
  3. 1
  4. 2

Correct answer

A. 12

12 views

MCQSEXAM

Explanation

The constructor prints first and the destructor prints when a leaves scope, producing 12.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C++ and Object-Oriented Programming MCQs

Practise all C++ and Object-Oriented Programming MCQs

Similar MCQs