Bird
0
0

Why does the expression 5 / 2 in C result in 2 instead of 2.5?

hard📝 Conceptual Q10 of 15
C - Operators and Expressions
Why does the expression 5 / 2 in C result in 2 instead of 2.5?
ABecause both operands are integers, so integer division truncates the decimal
BBecause C automatically rounds all divisions down
CBecause 5 and 2 are treated as floats by default
DBecause the division operator always returns an integer
Step-by-Step Solution
Solution:
  1. Step 1: Understand operand types in division

    Both 5 and 2 are integers, so C performs integer division.
  2. Step 2: Integer division truncates decimal part

    Integer division drops the decimal, so 5 / 2 = 2, not 2.5.
  3. Final Answer:

    Because both operands are integers, so integer division truncates the decimal -> Option A
  4. Quick Check:

    Integer division truncates decimals in C [OK]
Quick Trick: Integer division drops decimals, use float for decimals [OK]
Common Mistakes:
  • Thinking C rounds automatically
  • Assuming operands are floats
  • Believing division always returns int

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes