ProgrammingVery hard

char *a = "", *b = "abc"; if (strlen(a) - strlen(b) > 0) puts("longer"); else puts("not longer"); What is printed?

  1. A. not longer
  2. B. longer
  3. C. nothing, because the program does not compile
  4. D. undefined behaviour

Correct answer: B. longer

strlen returns size_t, so 0 - 3 wraps around to a huge positive value and the test is true. Unsigned subtraction never produces a negative result.

More C Programming questions

Exams that ask this topic