Do you know the answers to those ten questions about Initialization in Modern C++?

About  

I selected the following questions from 25 questions that you can find in my C++ Initialization Story book:


Print version @Amazon
C++ Initialization Story @Leanpub

Moreover, in the book, you can find a few coding exercises to practice skills.

The Quiz  

This quiz is only client-side; no data is sent anywhere.

1. Which C++ Standard did add in-class default member initializers?

2. Can you use auto type deduction for non-static data members?

3. Do you need to define a static inline data member in a cpp file?

4. Can a static inline variable be non-constant?

5. What's the output of the following code:

struct S {
    int a { 10 };
    int b { 42 };
};
S s { 1 };
std::cout << s.a << ", " << s.b;

6. Consider the following code:

struct C {
    C(int x) : a(x) { }
    int a { 10 };
    int b { 42 };
};
C c(0);

Select the true statement:

7. What happens when you throw an exception from a constructor?

8. What happens when you compile this code?

struct Point { int x; int y; };
Point pt {.y = 10, .x = 11 };
std::cout << pt.x << ", " << pt.y;

9. Will this code work in C++11?

struct User { std::string name = "unknown"; unsigned age { 0 }; };
User u { "John", 101 };

10. Assume you have a std::map<string, int> m;. Select the single true statement about the following loop:

for (const pair<string, int>& elem : m)

Summary  

I hope you enjoyed the quiz and got all answers correct :)

See more questions in the book: