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 is the result of using the macro BAND(++a) when a is initially 5?

  1. 6

  2. 7

  3. 8

  4. 0

The correct answer is: 8

When using the BAND macro, the number within the parentheses will be incremented by one and then bit-wise ANDed with the original number. In this case, the number within the parentheses is ++a, which means a will be incremented by one and then used in the operation. This means that a will become 6 when the macro is executed. 6 and 5 in binary form are 110 and 101, respectively. When these two numbers are bit-wise ANDed, the result is 100, which is equivalent to 4 in decimal form. Therefore, the result of using the BAND(++a) macro when a is initially 5 is 4, making option C the correct answer. Option A (6) is incorrect because it simply shows the value of a after the increment operation, without taking into account the bit-wise AND operation. Option B (7)