ProgrammingHardTCS NQT · Accenture

What is printed?

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

Correct answer: C. 1

x-- wraps 0 to 0xFFFFFFFF, and shifting right by 31 leaves the top bit, which is 1.

More C Programming questions

Exams that ask this topic