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!

Practice this question and more.


What does the bitwise NOT operator (~) do to its operand?

  1. Inverts each bit.

  2. Sets all bits to 1.

  3. Sets all bits to 0.

  4. Performs a logical negation.

The correct answer is: Inverts each bit.

The bitwise NOT operator (~) inverts each bit of its operand, resulting in a value that is the opposite of the original value. Option B is incorrect because it would result in a different value than inverting each bit. Option C is also incorrect for the same reason. Option D is incorrect because a logical negation simply reverses the boolean value of an operand, not its individual bits.