ProgrammingVery hardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    unsigned k = 0;
    int len = -1;
    printf("%d", k > len);
}
  1. A. 1
  2. B. 0
  3. C. 3
  4. D. 2

Correct answer: B. 0

len is converted to unsigned, so it becomes 4294967295 and 0 > 4294967295 is false. A signed comparison would say 0 > -1 is true.

More C Programming questions

Exams that ask this topic