ProgrammingHardTCS NQT · Infosys pattern
Assume a 64-bit LP64 ABI with natural alignment (no #pragma pack). What is printed?
Assume a 64-bit LP64 ABI with natural alignment (no #pragma pack). What is printed?
struct S {
char a;
int b;
char c;
};
printf("%zu", sizeof(struct S));- A. 6
- B. 12
- C. 9
- D. 8
Correct answer: B. 12
a@0 (1 byte, then 3 padding bytes so b aligns to 4), b@4 (4 bytes), c@8 (1 byte), then 3 trailing padding bytes so the whole struct's size is a multiple of its strictest alignment (4, from int): total 12.
More C Programming questions
- Assume a 64-bit LP64 ABI with natural alignment. What is printed? c struct S { int a; char b; int c; }; printf("%zu", sizeof(struct S));
- Assume a 64-bit LP64 ABI with #pragma pack(1) applied to this struct only. What is printed? c #pragma pack(push, 1) struct Packed { char…
- Assume a 64-bit LP64 ABI. What is printed? c struct A { char x; }; struct B { struct A a; char y; }; struct C { struct B b; char z; }…
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; struct Point p1 = {1, 2}; struct Point p2 = p1; p2.x = 99…
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { int data; struct Node next; }; printf("%zu", sizeof(struct Node));
- Assume a 64-bit LP64 ABI. What is printed? c struct Mixed { short s; char c; int i; }; struct Reordered { int i; short s; char c; }…