C programming — match each bitwise operator symbol in List I with its meaning in List II. List I (Operator) A. ~ B. & C. | D. ^ List II (Meaning) 1. Bitwise XOR 2. Bitwise AND 3. Bitwise OR 4. One's complement

Difficulty: Easy

Correct Answer: A-4, B-2, C-3, D-1

Explanation:


Introduction / Context:
Bitwise operators in C manipulate individual bits of integers. They are indispensable in embedded systems, device drivers, networking stacks, and performance-critical code where flags and masks are prevalent. This match-the-following tests recognition of the core operators and their semantics.


Given Data / Assumptions:

  • All operators apply to integer operands (signed or unsigned) in C.
  • Evaluation respects C operator precedence and usual integer promotions.
  • We focus on meaning, not precedence or side effects.


Concept / Approach:

The tilde (~) inverts every bit (one's complement). The ampersand (&) performs bitwise AND, setting a bit only if it is 1 in both operands. The vertical bar (|) performs bitwise OR, setting a bit if it is 1 in either operand. The caret (^) performs bitwise XOR, setting a bit if operands differ at that position.


Step-by-Step Solution:

Map ~ → one's complement → 4.Map & → bitwise AND → 2.Map | → bitwise OR → 3.Map ^ → bitwise XOR → 1.


Verification / Alternative check:

Quick test with an 8-bit example: let x = 0b10101010 and y = 0b11001100. Then ~x = 0b01010101, x & y = 0b10001000, x | y = 0b11101110, x ^ y = 0b01100110. These results align with the mapped meanings.


Why Other Options Are Wrong:

  • Swapping XOR with OR or AND changes truth conditions and would contradict these bit patterns.
  • Assigning ~ to logical NOT confuses bitwise (~) with logical (!) operators; here we operate on bits, not boolean truth values.


Common Pitfalls:

Confusing bitwise operators (&, |, ^) with their logical counterparts (&&, ||). Also, forgetting that ~ on signed integers is defined via two's complement representation and can produce negative values.


Final Answer:

A-4, B-2, C-3, D-1

More Questions from Matching Questions

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion