Lect2 Multidimarray Part3
Lect2 Multidimarray Part3
2-dimensional arrays
https://bohr.wlu.ca/cp264/notes/cp264_lecture07_array.ppt
3. Two-dimensional Arrays
A two-dimensional array is specified using two subscripts where one
subscript denotes row and the other denotes column.
Second/column Dimension
https://bohr.wlu.ca/cp264/notes/cp264_lecture07_array.ppt
Two-dimensional Arrays????
Therefore, a two dimensional m×n array is an array that contains
m×n data elements and each element is accessed using two
subscripts, i and j, where 0<= i<m and 0<= j<n
Example:
int marks[3][5];
https://bohr.wlu.ca/cp264/notes/cp264_lecture07_array.ppt
FIGURE 8-35 Array Of Arrays
• In the row-major order the elements of the first row are stored
before the elements of the second and third rows. That is, the
elements of the array are stored row by row where n elements of
the first row will occupy the first nth locations.
(0, 0) (0, 1) (0, 2) (0, 3) (1, 0) (1, 1) (1, 2) (1, 3) (2, 0) (2, 1) (2, 2) (2, 3)
https://bohr.wlu.ca/cp264/notes/cp264_lecture07_array.ppt
FIGURE 8-36 Memory Layout
int *p = &a[0][0];
(p+i*col+j) &a[i][j];
*(p+i*col+j) a[i][j];
Example: transpose of a matrix ?????
Pass by matrix name
void transpose(int n, int m[][n]) { // need declare n first
int *p = m, i = 0, j = 0, temp;
arr[i][j][k]= *(*(*(arr+i)+j)+k)