Quiz Entry - updated: 2026.07.10
How is the address of a 1-dimensional array element computed?
addr(name[i]) = name + i * sizeof(element) — start address plus index times element size.
* 1-D array: contiguous cells, addr(A[i]) = A + i * sizeof(element). *
An array is just a contiguous block of equally-sized elements, so finding element i is pure arithmetic — there's no metadata, no bounds info stored anywhere. For T name[N]:
- One element:
s_T = sizeof(T) - Whole array:
s_A = N * s_T - Element
i:addr_i = name + i * s_T
Memory layout:
name[0] name[1] name[2] ... name[N-1]
x x+s_T x+2*s_T x+(N-1)*s_T
Example: int A[100] based at 0x1000 (so s_T = 4):
A[5]is at0x1000 + 5*4 = 0x1014.
In assembly this becomes a scaled-index memory operand, e.g. movl A(,%rdi,4), %eax reads A[i] with %rdi = i and scale 4.
Alignment: the array's alignment equals the alignment of its element type T — there's no extra requirement just because it's an array.
Go deeper:
Array data structure (Wikipedia) — the array data structure and index-to-address formula.
Addressing mode (Wikipedia) — the scaled-index addressing mode used to reach an element.