ProgrammingHardTCS NQT · Infosys pattern

What is printed? (Assume int is 32 bits, two's complement.)

What is printed? (Assume int is 32 bits, two's complement.)
unsigned int a = 0xF0F0F0F0;
unsigned int b = a >> 4;
printf("%X", b);
  1. A. F0F0F0F
  2. B. FF0F0F0F
  3. C. 0F0F0F0F
  4. D. F0F0F0F0

Correct answer: C. 0F0F0F0F

a is unsigned, so >> is a LOGICAL shift: zeros fill from the left. 0xF0F0F0F0 >> 4 shifts every hex digit right by one position, bringing in a 0 at the top: 0x0F0F0F0F.

More C Programming questions

Exams that ask this topic