The value of the following C expression (13 / 4 * 3) % 5 + 1 is
2010
The value of the following C expression (13 / 4 * 3) % 5 + 1 is
Answer: D. 5 — ConceptIn C the multiplicative operators *, / and % all sit at the same precedence level, which is higher than +, and they associate from left to right. So a…
- A.
5.75
- B.
2.95
- C.
1.4875
- D.
5
Attempted by 164 students.
Show answer & explanation
Correct answer: D
Concept
In C the multiplicative operators *, / and % all sit at the same precedence level, which is higher than +, and they associate from left to right. So a chain a / b * c is grouped as (a / b) * c, and a % b + c is grouped as (a % b) + c.
Two type rules govern this family. When both operands of / are integers, C performs integer division: the quotient is truncated toward zero and the fractional part is discarded, never rounded. And % is defined only for integral operands; it returns the remainder of that same integer division, so a value carrying a fractional part can never be fed to % in a valid C expression.
Application
Evaluate the parenthesised part first: 13 / 4 * 3.
Inside it, / and * are equal in precedence and associate left to right, so 13 / 4 is taken first.
13 and 4 are both integer constants, so 13 / 4 is integer division: 13 = 3 × 4 + 1, so the quotient is 3 and the 0.25 is discarded.
Then 3 * 3 = 9, so the parenthesised part contributes the integer 9.
% outranks +, so 9 % 5 is evaluated next: 9 = 1 × 5 + 4, so the remainder is 4.
Finally 4 + 1 = 5.
Cross-check
Every operand at every step is an integer, so the expression cannot produce a fractional value. Testing the rejected reading: if 13 / 4 were the real number 3.25, the parenthesised part would be 9.75, and 9.75 % 5 would not even compile, because C refuses a floating-point operand for %. Two habits explain most wrong evaluations here:
Truncation, not rounding: 13 / 4 gives 3, not 4 — C discards the fraction rather than rounding it up.
% never yields a fraction: with a divisor of 5 the remainder is always one of 0, 1, 2, 3, 4, so adding 1 keeps the result a whole number.
The value of the expression is 5.