Difficulty: Easy
Correct Answer: A-3, B-2, C-4, D-1
Explanation:
Introduction / Context:
In C/C++ and embedded code, it is crucial to distinguish between logical operators (which evaluate truth values) and bitwise operators (which operate on individual bits). Misuse can cause subtle bugs in conditionals and bit manipulations.
Given Data / Assumptions:
Concept / Approach:
Map each operator to its canonical description: logical operators combine conditions; bitwise operators mask, set, or clear bits in flags and registers.
Step-by-Step Solution:
Verification / Alternative check:
Truth tables: for logical operators, results are 0/1 with short-circuit semantics. For bitwise operators, apply bit-level rules; e.g., 0b0101 | 0b0011 = 0b0111.
Why Other Options Are Wrong:
Swapping logical and bitwise categories mischaracterizes evaluation semantics and precedence, leading to logical errors in conditions and ISR flag handling.
Common Pitfalls:
Using & instead of && in if-statements, which evaluates both sides and returns a bitwise result; or using | instead of ||, defeating short-circuiting and potentially invoking unintended side effects.
Final Answer:
A-3, B-2, C-4, D-1
Discussion & Comments