ProgrammingHardGATE CS · Infosys

Assume uint32t is 32 bits. What is printed?

Assume uint32_t is 32 bits. What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
    uint32_t v = 0x12345678u;
    uint32_t r = (v >> 24) | ((v >> 8) & 0xFF00u) | ((v << 8) & 0xFF0000u) | (v << 24);
    printf("%X", (unsigned)r);
}
  1. A. 12345678
  2. B. 78563421
  3. C. 78563412
  4. D. 87654321

Correct answer: C. 78563412

The four bytes are reversed, so 0x12 0x34 0x56 0x78 becomes 0x78 0x56 0x34 0x12. Missing the middle masks would leave stray bits in the middle bytes.

More C Programming questions

Exams that ask this topic