Bird
Raised Fist0

What is the output of isPowerOfTwo(0) using the following code?

medium🧾 Code Trace Q4 of Q15
Bit Manipulation - Power of Two
What is the output of isPowerOfTwo(0) using the following code?
ATrue
BNone
CError
DFalse
Step-by-Step Solution
Solution:
  1. Step 1: Check input 0

    Since n = 0, the condition n <= 0 is True, so function returns False immediately.
  2. Step 2: Confirm output

    Function returns False, so print outputs False, no error occurs.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Zero is not a power of two, so output is False [OK]
Quick Trick: Zero is not power of two, returns False [OK]
Common Mistakes:
MISTAKES
  • Assuming zero is power of two
  • Confusing zero with one
Trap Explanation:
PITFALL
  • Some candidates think zero passes the bitwise check, but code handles zero explicitly.
Interviewer Note:
CONTEXT
  • Tests handling of edge cases like zero input.
Master "Power of Two" in Bit Manipulation

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bit Manipulation Quizzes