ProgrammingHardProduct company OA
Assume little-endian, 8-bit char and 32-bit unsigned int. What is printed?
Assume little-endian, 8-bit char and 32-bit unsigned int. What is printed?
union { unsigned int u; unsigned char b[4]; } x;
x.u = 0x11223344;
x.b[0] = 0xAA;
printf("%X %X", x.u, x.b[3]);- A. 112233AA 44
- B. 112233AA 11
- C. AA223344 11
- D. AA223344 AA
Correct answer: B. 112233AA 11
On a little-endian machine the lowest-addressed byte b[0] holds the least significant byte 0x44, so overwriting it gives 0x112233AA. b[3] is the most significant byte, 0x11. 'AA223344' is the big-endian picture.
More C Programming questions
- What is printed? c int a = 6, b = 2; int r = a & 3 << b | 1; printf("%d", r);
- What is printed? c int i = 1, j = 2, k = 3; int r = (i > j) ? i++ : j > k ? j++ : (k++, i + j + k); printf("%d %d %d %d", i, j, k, r);
- What is printed by r("ABCDE", 0)? c void r(const char s, int d) { if (!s) return; if (d % 2) putchar(s); r(s + 1, d + 1); if (d % 2 == 0)…
- What is printed? c int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int (r)[3] = m + 1; printf("%d %d %d", r[1][0], (r)[2], (r - 1) +…
- Which of these statements about C's dynamic-memory functions are correct? (i) realloc(NULL, n) behaves like malloc(n). (ii) If realloc…
- Why is the line p = realloc(p, 2 n sizeof p); considered unsafe?