14. The Final Quiz

Check your knowledge from this mini-book!

1. Which C++ Standard did add in-class default member initializers?
  1. C++98
  2. C++11
  3. C++14
  4. C++17
2. Can you use auto type deduction for non-static data members?
  1. Yes, since C++11
  2. No
  3. Yes, since C++20
3. Do you need to define a static inline data member in a separate cpp file?
  1. No, the definition happens at the same place where a static inline member is declared.
  2. Yes, the compiler needs the definition in a cpp file.
  3. Yes, the compiler needs a definition in all translation units that use this variable.
4. Can a static inline variable be non-constant?
  1. Yes, it’s just a regular variable.
  2. No, inline variables must be constant.
5. Consider the following code:
struct S {
    int a { 10 };
    int b { 42 };
};

What’s the output of the following line?

S s { 1 };
std::cout << s.a << ", " << s.b;
  1. 1, 0
  2. 10, 42
  3. 1, 42
6. Consider the following code:
class C {
    C(int x) : a(x) { }

    int a { 10 };
    int b { 42 };
};

C c(0);

More questions available in the full version of the book.