← 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;
}
- A.AAaa|
- B.AAa|a
- C.AaAa|
- 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 →