ProgrammingHardHCL · Tech Mahindra pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
union Data {
int i;
char c;
};
union Data d;
d.i = 0x12345678;
printf("%x", (unsigned char)d.c);- A. 12
- B. 34
- C. 56
- D. 78
Correct answer: D. 78
On a little-endian machine (standard for x86/x86-64), the least-significant byte of 0x12345678 (0x78) is stored at the lowest address, which is exactly where the single-byte member c overlaps; reading d.c (cast to unsigned char for the %x format) gives 0x78.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; void tryModify(struct Point p) { p.x = 999; } int main(void) {…
- Assume a 64-bit LP64 ABI. What is printed? c struct Rect { struct { int x, y; } topLeft; struct { int x, y; } bottomRight; }; struct Rect…
- Assume a 64-bit LP64 ABI. What is printed? c typedef struct { int code; char message[20]; } Error; Error makeError(int c, const char msg)…
- Assume a 64-bit LP64 ABI. What is printed? c struct Counter { int value; }; void increment(struct Counter c) { c->value++; } int…
- Assume a 64-bit LP64 ABI. What is printed? c struct Pair { int a, b; }; struct Pair swapPair(struct Pair p) { int tmp = p.a; p.a = p.b…
- Assume a 64-bit LP64 ABI. What is printed? c struct Employee { char name[20]; int id; float salary; }; struct Employee e1 = {"Alice", 101…