Which operator is used to perform bitwise NOT in C++?

int x=5;
cout << (~x);
                        

Options

  • A. &
  • B. |
  • C. ~
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. ~

Detailed Explanation

Answer: (C) ~

The tilde operator ~ performs a bitwise NOT operation.

Bitwise NOT changes every bit: 0 becomes 1 and 1 becomes 0.

For example, if a simplified bit pattern is 0101, applying ~ gives 1010.

The operators & and | perform bitwise AND and OR respectively.