ProgrammingHardHCL · Tech Mahindra pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
struct S { char c; int arr[2]; };
printf("%zu %zu", sizeof(struct S), offsetof(struct S, arr));
  1. A. 8 4
  2. B. 9 1
  3. C. 12 1
  4. D. 12 4

Correct answer: D. 12 4

c@0 (1 byte); arr needs 4-byte alignment, so it starts at offset 4 (3 padding bytes) and occupies 4-11 (two ints); end 12, already a multiple of 4.

More C Programming questions

Exams that ask this topic