ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: C. 1 1

sizeof yields an unsigned size_t, so -1 becomes SIZE_MAX in the comparison and 1 < SIZE_MAX is true. The second comparison is an ordinary signed comparison, so it is also 1.

More C Programming questions

Exams that ask this topic