🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: C++ Interview Questions: all 10 questions

Quiz: C++ Interview Questions · Question 1 of 10

What is printed? (code)

What is printed?

#include <iostream>
using namespace std;
struct P { P() { cout << "P"; } ~P() { cout << "p"; } };
struct C : P { C() { cout << "C"; } ~C() { cout << "c"; } };
int main() { C x; return 0; }
  1. A.CPpc
  2. B.PCcp
  3. C.PCpc
  4. D.CPcp
Answer & explanation

Correct answer: PCcp

Construct base then derived (PC); destroy derived then base (cp).

Can you get the rest right without peeking?

Take the timed Quiz: C++ Interview Questions quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →