All mock tests are FREE till 31 December — register to save your progress

With 1-byte chars, 2-byte shorts, 4-byte ints and 8-byte doubles, each aligned to its size, no field reordering, and padding for alignment, how much space does this array use? struct { short s; char c; short t; char d; double r; int i; } A[10];

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: C. 240 bytes

Explanation

s at 0–1, c at 2, pad, t at 4–5, d at 6, pad to 8, r at 8–15, i at 16–19, then pad to 24 so the next element's double is aligned. 24 × 10 = 240 bytes.

More Programming Languages and Computer Graphics questions