Bird
0
0

In C, which expression correctly uses operators to determine if an integer num is odd?

hard📝 Application Q8 of 15
C - Operators and Expressions
In C, which expression correctly uses operators to determine if an integer num is odd?
A(num / 2) == 0
B(num % 2) != 0
C(num & 1) == 0
D(num + 2) % 2 == 0
Step-by-Step Solution
Solution:
  1. Step 1: Understand odd number check

    An odd number has a remainder of 1 when divided by 2.
  2. Step 2: Use modulus operator

    The modulus operator % gives the remainder. So, num % 2 returns 1 for odd numbers.
  3. Step 3: Check if remainder is not zero

    If num % 2 != 0, then num is odd.
  4. Final Answer:

    (num % 2) != 0 -> Option B
  5. Quick Check:

    Odd numbers have remainder 1 when divided by 2 [OK]
Quick Trick: Use 'num % 2 != 0' to check odd numbers [OK]
Common Mistakes:
  • Using division instead of modulus operator
  • Checking for equality to zero instead of inequality
  • Using bitwise AND incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes