ProgrammingHardHCL · Tech Mahindra pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Node { char tag; struct Node *next; int val; };
printf("%zu", sizeof(struct Node));- A. 24
- B. 16
- C. 20
- D. 13
Correct answer: A. 24
tag@0 (1 byte), 7 bytes of padding so next can sit at the pointer-aligned offset 8, next@8 (8 bytes), val@16 (4 bytes), then 4 bytes of trailing padding to round the struct to a multiple of 8 (the pointer's alignment): 24 total.
More C Programming questions
- Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed? c #include <stddef.h> struct M { unsigned…
- Assume a 64-bit LP64 ABI. What is printed? c struct A { char a; double d; char b; }; struct B { double d; char a; char b; }; printf("%zu…
- On a little-endian 64-bit machine, what is printed? c union U { int i; struct { short lo; short hi; } s; }; union U u; u.i = 0x00020001…
- Assume unsigned int bitfields pack into 32-bit units and a 64-bit LP64 ABI. What is printed? c struct N { unsigned a:20; int b; }…
- Assume a 64-bit LP64 ABI (8-byte long long, natural alignment). What is printed? c struct LL { char a; long long b; char c; }…
- Assume a 64-bit LP64 ABI. What is printed? c union Val { int i; float f; }; union Val arr[4]; printf("%zu %zu", sizeof(union Val)…