ProgrammingVery hardCompetitive coding (CP)

What is printed? Assume unsigned int is 32 bits.

What is printed? Assume unsigned int is 32 bits.
#include <stdio.h>
int main(void) {
    unsigned x = 0xABCD;
    printf("%u", (x >> 5) & 7u);
}
  1. A. 6
  2. B. 7
  3. C. 5
  4. D. 0

Correct answer: A. 6

0xABCD >> 5 is 0x55E, and its low three bits are 110, which is 6. Using the high bits instead of the low bits would give a different field.

More C Programming questions

Exams that ask this topic