ProgrammingHardProduct-company MCQ pattern

On a little-endian 64-bit machine, what is printed?

On a little-endian 64-bit machine, what is printed?
union U { int i; char c[4]; };
union U u;
u.i = 0x41424344;
printf("%c%c%c%c", u.c[0], u.c[1], u.c[2], u.c[3]);
  1. A. ABCD
  2. B. DCBA
  3. C. ABDC
  4. D. CDAB

Correct answer: B. DCBA

Little-endian storage puts the least-significant byte first: the bytes in memory are 0x44, 0x43, 0x42, 0x41, which are the ASCII codes for 'D', 'C', 'B', 'A' respectively.

More C Programming questions

Exams that ask this topic