ProgrammingModerateAccenture · Capgemini pattern

What is printed?

What is printed?
unsigned x = 0xF0;      /* 32-bit unsigned */
printf("%u %u %u %u", x >> 4, x << 1, x & 0x3C, x | 0x0F);
  1. A. 15 224 48 255
  2. B. 240 480 60 255
  3. C. 15 480 48 255
  4. D. 15 480 60 255

Correct answer: C. 15 480 48 255

0xF0 = 1111 0000 (240). >> 4 gives 0000 1111 = 15. << 1 doubles it to 480; x is a 32-bit unsigned, so nothing is lost (224 would be an 8-bit wrap). 1111 0000 & 0011 1100 = 0011 0000 = 48. 1111 0000 | 0000 1111 = 255.

More C Programming questions

Exams that ask this topic