← 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; }
- A.CPpc
- B.PCcp
- C.PCpc
- 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 →