ProgrammingModerateTCS NQT · Wipro

What is printed?

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

Correct answer: D. -6

Division and remainder truncate toward zero, so -8 / 2 = -4 and -8 % 3 = -2. The sum is -6, and a floor-based remainder would give -2 and a different total.

More C Programming questions

Exams that ask this topic