ProgrammingVery hardGATE CS · Product company OA

For ints a and b with b != 0 and no overflow, which statement is always true in C99 and later?

  1. A. a % b is never negative
  2. B. a / b rounds toward negative infinity
  3. C. (a / b) * b + a % b == a
  4. D. a % b always has the sign of b

Correct answer: C. (a / b) * b + a % b == a

C99 makes integer division truncate toward zero and defines % so that this identity holds. As a result a % b takes the sign of a (−7 % 2 is −1), not of b, and it can be negative.

More C Programming questions

Exams that ask this topic