ProgrammingVery hard

printf("%d %d", -17 % 5, 17 % -5); What is printed in C99?

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

Correct answer: C. -2 2

C99 truncates toward zero, so -17 / 5 = -3 and -17 % 5 = -17 + 15 = -2. The sign of 17 % -5 follows 17, giving 2.

More C Programming questions

Exams that ask this topic