ProgrammingVery hardGATE CS · TCS NQT

What is printed?

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

Correct answer: D. 1

sizeof yields an unsigned size_t, so sizeof(char) - 2 wraps to a huge value, which is greater than 0. Assuming a signed result would give 0.

More C Programming questions

Exams that ask this topic