ProgrammingVery hardProduct company OA
On a typical x86-64 GCC/Clang target, what is printed?
On a typical x86-64 GCC/Clang target, what is printed?
struct F {
unsigned a : 20;
unsigned b : 20;
};
printf("%zu", sizeof(struct F));- A. 4
- B. 8
- C. 5
- D. 10
Correct answer: B. 8
a:20 fills most of the first 32-bit allocation unit, leaving only 12 bits — not enough room for b:20, which (being the same declared type) must start a new unsigned-sized unit rather than straddle the boundary. Two 4-byte units are used: 8 bytes total.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct S { char c; int arr[2]; }; printf("%zu %zu", sizeof(struct S), offsetof(struct S, arr));
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { int val; struct Node next; }; printf("%zu", sizeof(struct Node));
- What is printed? c #pragma pack(push, 1) struct Packed { char c; int i; }; #pragma pack(pop) printf("%zu", sizeof(struct Packed));
- Assume a 64-bit LP64 ABI and 1-byte Bool. What is printed? c struct S { Bool b; double d; }; printf("%zu", sizeof(struct S));
- Assume enum's underlying type is int (typical on common compilers) and a 64-bit LP64 ABI. What is printed? c enum Color { RED, GREEN, BLUE…
- Assume a 64-bit LP64 ABI. What is printed? c struct Pt { int x, y; }; struct Pt pts[4]; printf("%ld", (long)((char)&pts[2]…