ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    printf("%d", (-17 / 5) * 5 + (-17 % 5) == -17);
}
  1. A. 0
  2. B. 2
  3. C. 1
  4. D. 3

Correct answer: C. 1

C99 division truncates toward zero, so -17 / 5 = -3 and -17 % 5 = -2. Then (-3) * 5 + (-2) = -17, so the identity holds.

More C Programming questions

Exams that ask this topic