ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned n = 2;
    if (n - 3 < 5) puts("small");
    else puts("big");
}
  1. A. small
  2. B. big
  3. C. both
  4. D. neither

Correct answer: B. big

n - 3 is unsigned and wraps to 4294967295, which is not less than 5, so the program prints big. A signed analysis would wrongly predict small.

More C Programming questions

Exams that ask this topic