ProgrammingHardCompetitive coding (CP)

What is printed?

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

Correct answer: B. 1

a - b wraps to SIZE_MAX - 1, and halving that value still leaves a huge number, which is greater than 0. Treating the difference as a signed value would give -1 and a false test, printing 0.

More C Programming questions

Exams that ask this topic