ProgrammingVery hardProduct company OA

What is printed?

What is printed?
size_t a = 3, b = 5;
if (a - b > 0) puts("bigger");
else puts("smaller");
  1. A. Compilation error
  2. B. Undefined behaviour
  3. C. bigger
  4. D. smaller

Correct answer: C. bigger

size_t is unsigned, so 3 − 5 wraps to a huge positive value (SIZE_MAX − 1), which is greater than 0. Unsigned wrap-around is well defined. To compare sizes, write a > b instead of subtracting.

More C Programming questions

Exams that ask this topic