ProgrammingModerateTCS NQT · Wipro

What is printed?

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

Correct answer: C. 0

(unsigned)-1 is 4294967295, which is not less than 3, so the test is 0. The array a is never indexed here.

More C Programming questions

Exams that ask this topic