ProgrammingHardTCS NQT · Wipro

What is printed?

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

Correct answer: D. 2

!0x80 is 0, so !!0x80 normalises the nonzero value to 1; !0 is 1 and !-1 is 0 because any nonzero value is true. The total is 2, and 3 wrongly treats !-1 as 1.

More C Programming questions

Exams that ask this topic