ProgrammingHardGATE CS · Campus placements

unsigned int n = 3u; int k = -1; if (k > n) printf("yes"); else printf("no"); What is printed?

  1. A. prints yes
  2. B. prints no
  3. C. compile error
  4. D. undefined behaviour

Correct answer: A. prints yes

k is converted to unsigned for the comparison, giving UINT_MAX, which is greater than 3. The condition is true and the program prints yes.

More C Programming questions

Exams that ask this topic