C++ Quiz15 of 173
Difficulty:
⬅️ Prev: 15Quiz ID: 16Next: 17 ➡️

According to the C++23 standard, what is the output of this program?

#include <iostream>

class A {
public:
  A() { std::cout << 'a'; }
  ~A() { std::cout << 'A'; }
};

class B {
public:
  B() { std::cout << 'b'; }
  ~B() { std::cout << 'B'; }
  A a;
};

int main() { B b; }
Hint

When are member variables initialized and destroyed?

Reveal answer

abBA

Explanation

Member variables are initialized before the constructor is called. The destructor is called before member variables are destroyed.

⬅️ Prev: 15Quiz ID: 16Next: 17 ➡️