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

Quiz: C++ Classes and Objects · Question 3 of 10

What does this print? (code)

What does this print?

#include <iostream>
using namespace std;
class A {
public:
    A() { cout << "A"; }
    ~A() { cout << "a"; }
};
int main() {
    A x;
    { A y; }
    cout << "|";
    return 0;
}
  1. A.AAaa|
  2. B.AAa|a
  3. C.AaAa|
  4. D.A|Aaa
Answer & explanation

Correct answer: AAa|a

x is built (A), y is built (A) and destroyed at its block end (a), then "|", then x is destroyed (a).

Can you get the rest right without peeking?

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

Start the quiz →