1. Arrays and address calculation
An array stores elements of one type in consecutive memory. Element access is because its address is computed directly. Inserting or deleting in the middle is because elements must shift.
For a 1-D array A[l..u] with base address and element size : .
For a 2-D array A[l1..u1][l2..u2] with rows and columns:
- Row-major (C): rows are laid out one after another, .
- Column-major (Fortran): columns one after another, .
The idea: count how many elements come before the target, then multiply by . For 3-D arrays apply the same idea: in row-major A[i][j][k] the number before it is (with zero-based indices).
In C, a[i] means *(a + i), and for int a[m][n], a[i][j] is at offset elements from a. Watch for lower bounds that are not 0 or 1, including negative ones.