ProgrammingHardHCL · Tech Mahindra pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct S { char c; int arr[2]; };
printf("%zu %zu", sizeof(struct S), offsetof(struct S, arr));- A. 8 4
- B. 9 1
- C. 12 1
- D. 12 4
Correct answer: D. 12 4
c@0 (1 byte); arr needs 4-byte alignment, so it starts at offset 4 (3 padding bytes) and occupies 4-11 (two ints); end 12, already a multiple of 4.
More C Programming questions
- 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]…
- Assume a 64-bit LP64 ABI. What is printed? c struct Vec3 { double x, y, z; }; struct Mesh { struct Vec3 verts; int count; }; printf("%zu…