ProgrammingHardTCS NQT · Infosys

int a = -7, b = 2; What is a / b * b + a % b?

  1. A. 0
  2. B. -6
  3. C. 5
  4. D. -7

Correct answer: D. -7

C division truncates toward zero, so a / b is -3 and a % b is -1. The identity (a / b) * b + a % b = a holds, so the result is -7.

More C Programming questions

Exams that ask this topic