ProgrammingHardGATE CS · TCS NQT

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    printf("%d", ~5 & 0xF);
}
  1. A. 10
  2. B. 11
  3. C. -6
  4. D. 5

Correct answer: A. 10

~5 is -6, whose low four bits are 1010, so the mask gives 10. The value 11 comes from the bit pattern 1011 being read with the wrong mask.

More C Programming questions

Exams that ask this topic