ProgrammingVery hardTCS NQT · Infosys pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Node { int val; struct Node *next; };
printf("%zu", sizeof(struct Node));- A. 12
- B. 16
- C. 8
- D. 24
Correct answer: B. 16
val@0 (4 bytes). next is a pointer (align 8), so it cannot start at offset 4; it's pushed to offset 8 (4 padding bytes) and occupies 8-15. End is already 16, a multiple of 8.
More C Programming questions
- 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…
- What is printed? c unsigned char x = 0xF0; printf("%d", (x ^ 0xFF) & 0x0F);