Bird
0
0

Given the code:

hard📝 Application Q9 of 15
C - Operators and Expressions
Given the code:
int a = 8, b = 3;
int result = a / b * b + a % b;
printf("%d", result);

What is the output and why?
A2, because of incorrect calculation
B9, due to operator precedence
C8, because integer division and modulus reconstruct the original number
D3, as remainder only
Step-by-Step Solution
Solution:
  1. Step 1: Calculate integer division and multiplication

    a / b = 8 / 3 = 2 (integer division), then 2 * 3 = 6.
  2. Step 2: Calculate modulus and add

    a % b = 8 % 3 = 2, so 6 + 2 = 8.
  3. Final Answer:

    8, because integer division and modulus reconstruct the original number -> Option C
  4. Quick Check:

    a/b*b + a%b = a [OK]
Quick Trick: Integer division * divisor + remainder = original number [OK]
Common Mistakes:
  • Misunderstanding integer division
  • Ignoring operator precedence
  • Confusing remainder with quotient

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes