ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned a = 7;
    printf("%u", a / 2 * 2);
}
  1. A. 7
  2. B. 1
  3. C. 6
  4. D. 3

Correct answer: C. 6

/ and * have equal precedence and group left to right, so 7 / 2 = 3 (truncated), then 3 * 2 = 6. 7 assumes the / 2 and * 2 cancel, 1 groups it as 7 / (2 * 2), and 3 stops after the division.

More C Programming questions

Exams that ask this topic