Subject / 929 questions

Programming MCQs

Page 6 of Programming multiple-choice questions with answers. Tap an option to check yourself.

Page 6 of 47

Question 101 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 112 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 115 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 118 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 120 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