ProgrammingHardTCS NQT · Infosys

int a = -7, b = 2; printf("%d %d", a / b, a % b); prints what?

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

Correct answer: C. -3 -1

Since C99, integer division truncates toward zero, so -7 / 2 is -3 and the remainder takes the sign of the dividend: -7 = (-3)(2) + (-1).

More C Programming questions

Exams that ask this topic