ProgrammingHardHCL · Tech Mahindra pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct Node {
int value;
struct Node *next;
};
printf("%zu", sizeof(struct Node));- A. 12
- B. 8
- C. 16
- D. 4
Correct answer: C. 16
value is a 4-byte int at offset 0; next is an 8-byte pointer, which needs 8-byte alignment, so 4 bytes of padding are inserted before it, placing next at offset 8. Total used: 16 bytes, already a multiple of 8 (the struct's strictest alignment), so sizeof = 16.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c typedef union { struct { unsigned char r, g, b, a; } channels; unsigned int packed; } Color…
- What is printed? c #define SQUARE(x) x x int main() { int a = 5; printf("%d", SQUARE(a + 1)); }
- What is printed? c #define INCR(x) x++ int main() { int i = 5; int r = 2 INCR(i); printf("%d %d", r, i); }
- What is printed? c #define PR(x) printf(#x " = %dn", x) int main() { int value = 42; PR(value); }
- What is printed? c #define CONCAT(a, b) a##b int main() { int xy = 100; printf("%d", CONCAT(x, y)); }
- What is printed? c #define ISEVEN(n) ((n) % 2 == 0) int main() { int x = 7; if (!ISEVEN(x)) printf("odd"); else printf("even"); }