ProgrammingHardHCL · Tech Mahindra pattern

Assume 64-bit LP64, natural alignment. What is printed?

Assume 64-bit LP64, natural alignment. What is printed?
struct S { double d; int i; };
struct S arr[3];
printf("%zu %zu", sizeof(struct S), sizeof(arr));
  1. A. 12 36
  2. B. 16 48
  3. C. 12 48
  4. D. 16 36

Correct answer: B. 16 48

S: d@0 (8 bytes), i@8 (4 bytes), padded to 16 (a multiple of 8, double's alignment) so that an ARRAY of S keeps every element's double correctly aligned. sizeof(arr) = 3 * 16 = 48.

More C Programming questions

Exams that ask this topic