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.


What should you do to prevent the unexpected evaluation order of arguments in macros?

  1. Use functions instead of macros.

  2. Use parentheses around all expressions in the macro.

  3. Declare macros within a function body.

  4. Avoid using expressions as macro arguments.

The correct answer is: Use parentheses around all expressions in the macro.

Parentheses should be used around all expressions in the macro to specify the evaluation order. This is because macros perform a direct substitution of its arguments into the code, and without proper parentheses, the order of evaluation can be affected. Option A is incorrect because functions follow a strict evaluation order, which is not required for macros. Option C is incorrect because declaring macros within a function body does not affect the evaluation order of its arguments. Option D is incorrect because expressions are commonly used as macro arguments and avoiding them may not always be feasible.