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

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

Master C++ with our comprehensive quiz based on 'Thinking in C++'. Test your knowledge through flashcards and multiple-choice questions to enhance your understanding of C++. Prepare effectively for your exam!

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.


Which of the following is not a limitation of preprocessor macros?

  1. Lack of type safety.

  2. Unable to access class private members.

  3. Automatic inline expansion by the compiler.

  4. Side effects due to multiple evaluations of arguments.

The correct answer is: Automatic inline expansion by the compiler.

Preprocessor macros can be used by the compiler to alter the source code before it is compiled. However, there are some limitations that can make macros less flexible and powerful than other methods of code generation. One of these limitations is the lack of type safety, which can lead to errors in the code. Another limitation is the inability to access class private members, which may limit the functionality of macros in object-oriented programs. A third limitation is the possibility of side effects due to multiple evaluations of arguments, which can cause unexpected behavior in the code. However, automatic inline expansion by the compiler is not a limitation of preprocessor macros. In fact, this feature can often improve the performance of macros by reducing function call overhead. Therefore, it is not a correct answer to the question about limitations of preprocessor macros.