Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How does C++ ensure safety and scoping for inline functions, unlike preprocessor macros?

  1. By using the preprocessor for expansion.

  2. By controlling macro expansion through the compiler.

  3. By allowing inline functions to access only public members.

  4. By automatically converting all functions to inline.

The correct answer is: By controlling macro expansion through the compiler.

C++ ensures safety and scoping for inline functions by controlling macro expansion through the compiler. This means that the compiler checks for any potential conflicts or issues that may arise when using inline functions, ensuring that they are used in a safe and efficient manner. The other options may seem like possibilities, but they do not accurately describe how C++ handles inline functions. Option A is incorrect because using the preprocessor for expansion can lead to issues with duplicate code and potentially unsafe functionality. Option C is incorrect because inline functions can access any members, including private ones, as long as they are declared inline. Option D is incorrect because C++ does not automatically convert all functions to inline; it is up to the programmer to decide which functions should be declared inline.