ProgrammingHardWipro · Cognizant pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Node {
int data;
struct Node *next;
};
printf("%zu", sizeof(struct Node));- A. 8
- B. 16
- C. 12
- D. 4
Correct answer: B. 16
data@0 (4 bytes), then 4 bytes of padding so the 8-byte-aligned pointer next can start at offset 8, next@8 (8 bytes): total 16, already a multiple of 8 (the struct's strictest alignment, from the pointer).
More C Programming questions
- 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…
- Assume a 64-bit LP64 ABI. What is printed? c struct A { int x; }; struct B { struct A a; }; struct B b1 = {{10}}; struct B b2 = b1; b2.a.x…
- Assume a 64-bit LP64 ABI. What is printed? c struct S { double d; char c; }; struct S arr[2]; printf("%zu %ld", sizeof(arr), (char…
- Assume a 64-bit LP64 ABI. What is printed? c union Shape { struct { double radius; } circle; struct { double width, height; } rect; }…
- Assume 32-bit int and two's complement. What is printed? c int x = 5; int y = ~x + 1; printf("%d", y);