SLIDE 1
11/5/15 1
More ¡data ¡layout! Array ¡Layout
Array ¡ of ¡data ¡type ¡T ¡and ¡length ¡N Contiguously allocated ¡memory ¡ region ¡of ¡N ¡* ¡(size ¡of ¡T ¡in ¡bytes)
5 char a[12] x x ¡+ ¡12 int b[5] x x ¡+ ¡4 x ¡+ ¡8 x ¡+ ¡12 x ¡+ ¡16 x ¡+ ¡20 double c[3]
x ¡+ ¡24
x x ¡+ ¡8 x ¡+ ¡16 short* d[3] x x ¡+ ¡4 x ¡+ ¡8 x ¡+ ¡12
Two-‑Dimensional ¡Arrays
Declaration
2D ¡array ¡of ¡data ¡type ¡T R ¡rows, ¡C ¡columns Type ¡T ¡element ¡requires ¡K ¡bytes
Array ¡ layout ¡ and ¡size?
6
A[0][0] A[0][C-1] A[R-1][0]
- • •
- • • A[R-1][C-1]
- Nested ¡Arrays (C)
Declaration
2D ¡array ¡of ¡data ¡type ¡T R ¡rows, ¡C ¡columns Type ¡T ¡element ¡requires ¡K ¡bytes
Layout
Row-‑major ¡ordering
7
int A[R][C];
- • •
A [0] [0] A [0] [C-1]
- • •
A [1] [0] A [1] [C-1]
- • •
A [R-1] [0] A [R-1] [C-1]
- •
- A[0][0]
A[0][C-1] A[R-1][0]
- • •
- • • A[R-1][C-1]