C++ Quiz5 of 173
Difficulty:
⬅️ Prev: 4Quiz ID: 5Next: 6 ➡️

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

#include <iostream>

struct A {
  A() { std::cout << "A"; }
};
struct B {
  B() { std::cout << "B"; }
};

class C {
public:
  C() : a(), b() {}

private:
  B b;
  A a;
};

int main()
{
    C();
}
Hint

What determines the order of member variable initialization?

Reveal answer

BA

Explanation

The initialization order of member variables is determined by their order of declaration, not their order in the initialization list.

⬅️ Prev: 4Quiz ID: 5Next: 6 ➡️