# Multiple choice question.

• 02-17-2010
ungalnanban
Multiple choice question.
Dear Friends, I want to know witch one of the following choice is correct answer for the following sample code.

Sample Code

Code:

int sum_matrix (int m [][][], int 12, int y, int z){
int sum = 0;
int i, j, k;
for (k = 0; k <z; k++)
for (j = 0; j <y; j++)
for (i = 0; i <x; i++)
sum += m[k][j][i];

return sum;
}

Question Which one of the following accurately describes the error in
the function sum_matrix(), defined above?

Choice 1 (_)
The manner in which m is accessed by its indices does not parallel the
loop structure and may not produce the desired sum.
Choice 2 (_)
The matrix m has more dimensions than Standard C requires compliant
compilers to support.
Choice 3 (_)
The compiler lacks sufficient information to generate pointer
arithmetic code for m.
Choice 4 (_)
C does not support multidimensional arrays; it only supports arrays of
arrays.
Choice 5 (_)
Assuming that x, y, and z represent the bounds of the array, an
• 02-17-2010
quzah
Code:

int sum_matrix (int m [][][], int 12, int y, int z){
int sum = 0;
int i, j, k;
for (k = 0; k <z; k++)
for (j = 0; j <y; j++)
for (i = 0; i <x; i++)
sum += m[k][j][i];

return sum;
}

Choice 6 - None of the above.

Quzah.
• 02-18-2010
Salem
Try compiling it, and figure out the answer from the error message you get.

It is one of the answers listed.