ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI with natural alignment. What is printed?
Assume a 64-bit LP64 ABI with natural alignment. What is printed?
struct S {
int a;
char b;
int c;
};
printf("%zu", sizeof(struct S));- A. 9
- B. 12
- C. 10
- D. 8
Correct answer: B. 12
a@0 (4 bytes), b@4 (1 byte, then 3 padding bytes so c aligns to 4), c@8 (4 bytes). Total used is 12, which is already a multiple of 4, so no further trailing padding is needed: sizeof = 12.
More C Programming questions
- 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; }…
- Assume a 64-bit LP64 ABI. What is printed? c struct S { int a; int b; }; struct S arr[3] = {{1,2},{3,4},{5,6}}; int p = (int )arr…