ProgrammingVery hard
struct T { int a; double d; }; printf("%d", (int)(sizeof(struct T) == 16)); What is printed with 4-byte int and 8-byte double (natural alignment)?
- A. 0
- B. 12
- C. 8
- D. 1
Correct answer: D. 1
a takes 4 bytes, then 4 bytes of padding align d to 8, which takes 8 bytes, for a total of 16.
More C Programming questions
- struct F { char c; double d; }; printf("%zu", sizeof(struct F)); What is printed with natural alignment and 8-byte double?
- 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"…