ProgrammingHardProduct company OA
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Variant {
int type;
union { int i; float f; double d; };
};
printf("%zu", sizeof(struct Variant));- A. 12
- B. 16
- C. 8
- D. 24
Correct answer: B. 16
type@0 (4 bytes); the anonymous union's strictest member is double, so it needs 8-byte alignment and the union itself is 8 bytes, placed at offset 8 after 4 bytes of padding. Total size is 16.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { char tag; struct Node next; int val; }; printf("%zu", sizeof(struct Node));
- Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed? c #include <stddef.h> struct M { unsigned…
- Assume a 64-bit LP64 ABI. What is printed? c struct A { char a; double d; char b; }; struct B { double d; char a; char b; }; printf("%zu…
- On a little-endian 64-bit machine, what is printed? c union U { int i; struct { short lo; short hi; } s; }; union U u; u.i = 0x00020001…
- Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed? c struct N { unsigned a:20; int b; }…
- Assume a 64-bit LP64 ABI (8-byte long long, natural alignment). What is printed? c struct LL { char a; long long b; char c; }…