ProgrammingVery hard

For the signed integer -17, which expression gives the non-negative remainder modulo 5 in C?

  1. A. -17 % 5
  2. B. (-17 / 5) * 5
  3. C. ((-17 % 5) + 5) % 5
  4. D. -17 >> 2

Correct answer: C. ((-17 % 5) + 5) % 5

C99 gives -17 % 5 = -2, which is negative. Adding 5 and taking % again yields 3, the mathematical residue.

More C Programming questions

Exams that ask this topic