ProgrammingHardGATE CS · TCS NQT

What is printed?

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

Correct answer: D. 15

(unsigned)-1 is 0xFFFFFFFF, and a right shift by 28 keeps the top four bits, 0xF = 15. Shifting a signed negative value would not be portable, which is why the cast comes first.

More C Programming questions

Exams that ask this topic