ProgrammingHard

In C99 and later, what are the values of (-7) / 2 and (-7) % 2?

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

Correct answer: B. -3 and -1

Division truncates toward zero, so -7 / 2 = -3, and the remainder keeps the sign of the dividend, -7 - (-3)(2) = -1.

More C Programming questions

Exams that ask this topic