Multi dimensional Arrays Flashcards
pointer arrays vs Multidimensional
Pointer arrays, are one-dimensional arrays of pointers that refer a number
of individually contiguous memory blocks that are not contiguous collectively
Multi-dimensional are true array types where all of the data stored in the array occupies a
single contiguous block of memory
data type
2D array with 5 columns and three
rows. Such an array of elements of type T would have the array type T[3][5].
Passing an Array to a Function using an Array Parameter
void pass_as_array ( float x [10][10]) {
x [3][6] = 451.0;
}
We can leave the left-most (and only the left-most)
index in the parameter empty, and accept arrays with 10 columns and any number of rows like this
void pass_as_array ( float x [][10] , int num_rows ) {
x [3][6] = 451.0;
}
Passing an Array to a Function using a Pointer Parameter
void pass_as_pointer ( float *x, int num_rows , int num_cols ) {
x[3 * num_cols + 6] = 451.0;
}
elements of array through pointer
g 2D array with N rows and M columns, the 1D linear index of the 2D
index [r][c] is:
r . M+c
3D, the linear index of the 3D index [p][r][c] of an array with L planes, N rows and M columns is:
p . (N . M)+r . M+c