Practice mode C++

What type does auto deduce in the C++17 declaration auto x = {1, 2, 3};?

Correct answer D. std::initializer_list<int>

Explanation

With copy-list-initialisation (auto x = {...}), auto deduces std::initializer_list, here std::initializer_list, which needs . It never deduces a std::vector or a built-in array. C++17 also changed direct-list-initialisation, so auto y{5}; deduces int, and auto z{1, 2}; is an error, which surprises many programmers.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.