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));
  1. A. 12
  2. B. 8
  3. C. 16
  4. 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

Exams that ask this topic