ProgrammingHardTCS NQT · Infosys

What does printf("%d", -5 % 3) print?

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

Correct answer: A. -2

C division truncates toward zero, so -5 / 3 is -1 and -5 % 3 is -5 - (-1 * 3) = -2. The sign follows the dividend.

More C Programming questions

Exams that ask this topic