ProgrammingHard
struct F { char c; double d; }; printf("%zu", sizeof(struct F)); What is printed with natural alignment and 8-byte double?
- A. 16
- B. 9
- C. 12
- D. 8
Correct answer: A. 16
c is at offset 0, d is aligned to offset 8, and the total of 16 is a multiple of 8.
More C Programming questions
- struct G { int x; char y[3]; }; printf("%zu", sizeof(struct G)); What is printed with 4-byte int and natural alignment?
- struct H { short s; char c; }; printf("%zu", sizeof(struct H)); What is printed with 2-byte short and natural alignment?
- union U { int i; char c[6]; }; printf("%zu", sizeof(union U)); What is printed with 4-byte int and 1-byte char?
- struct E { int n; int a[]; }; printf("%zu", sizeof(struct E)); What is printed for a struct with a flexible array member and 4-byte int?
- struct K { int k; }; struct K list[3] = {{3}, {1}, {2}}; int sum = 0; for (int i = 0; i < 3; i++) sum = sum 10 + list[i].k; printf("%d"…
- struct Acc { int bal; }; void add(struct Acc a, int x) { a.bal += x; } struct Acc acc = {10}; add(acc, 5); printf("%d", acc.bal); What is…