ProgrammingHardProduct company OA

Assume 32-bit unsigned int. What is printed?

Assume 32-bit unsigned int. What is printed?
unsigned x = 0xABCD;
printf("%X %X", (x >> 4) & 0xF, (x & ~(0xFu << 8)) | (0x3u << 8));
  1. A. C A3CD
  2. B. B A3CD
  3. C. C ABCD
  4. D. D A3CD

Correct answer: A. C A3CD

(x >> 4) & 0xF extracts the second nibble from the right, C. The mask ~(0xF << 8) clears bits 8 to 11 (the B), giving 0xA0CD, and OR-ing 0x300 writes 3 there: 0xA3CD. 'B' picks the third nibble instead.

More C Programming questions

Exams that ask this topic