ProgrammingVery hard

In C99, what are the values of -8 % 3 and 8 % -3?

  1. A. 1 and -1
  2. B. -3 and -2
  3. C. -2 and 2
  4. D. 3 and 1

Correct answer: C. -2 and 2

The sign of % follows the dividend, so -8 % 3 = -2 and 8 % -3 = 2. Floor-based languages would give 1 and -1.

More C Programming questions

Exams that ask this topic