Topic / 110 questions

C++ MCQs

Page 2 of C++ multiple-choice questions with answers. Tap an option to check yourself.

Page 2 of 6

Question 21 C++

Which statement about C++ references is correct?

Correct answer D. A reference must be initialised when declared and cannot later be made to refer to another object

Open question
Advertisement
Advertisement
Question 32 C++

Why is it recommended to catch exceptions by reference, as in catch (const std::exception& e)?

Correct answer A. To avoid copying and object slicing so the derived exception's behaviour is preserved

Open question
Question 35 C++

What does the override specifier on a member function tell the C++ compiler?

Correct answer D. That the function must override a base class virtual function, or compilation fails

Open question
Advertisement
Question 38 C++

In modern C++, what is the main language-level guarantee of declaring a function inline?

Correct answer A. It may be defined in several translation units without violating the one-definition rule

Open question
Question 40 C++

Two objects hold std::shared_ptr references to each other. What problem does this cause and what is the usual fix?

Correct answer B. A reference cycle prevents either object being freed; make one link a std::weak_ptr

Open question