Multi dimensional Arrays Flashcards

1
Q

pointer arrays vs Multidimensional

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

data type

A

2D array with 5 columns and three
rows. Such an array of elements of type T would have the array type T[3][5].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Passing an Array to a Function using an Array Parameter

A

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;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Passing an Array to a Function using a Pointer Parameter

A

void pass_as_pointer ( float *x, int num_rows , int num_cols ) {
x[3 * num_cols + 6] = 451.0;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

elements of array through pointer

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly