Here is a listing of C multiple choice questions on “Multidimensional Arrays” along with answers, explanations and/or solutions:
1. What is the correct syntax to send a 3-dimensional array as a parameter? (Assuming declaration int a[5][4][3];)
a) func(a);
b) func(&a);
c) func(*a);
d) func(**a);
Answer: a
Clarification: None.
2. What are the applications of a multidimensional array?
a) Matrix-Multiplication
b) Minimum Spanning Tree
c) Finding connectivity between nodes
d) All of the mentioned
Answer: d
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int ary[2][3];
-
foo(ary);
-
}
-
void foo(int *ary[])
-
{
-
int i = 10, j = 2, k;
-
ary[0] = &i;
-
ary[1] = &j;
-
*ary[0] = 2;
-
for (k = 0;k < 2; k++)
-
printf("%dn", *ary[k]);
-
}
a) 2 2
b) Compile time error
c) Undefined behaviour
d) 10 2
Answer: a
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int ary[2][3];
-
foo(ary);
-
}
-
void foo(int (*ary)[3])
-
{
-
int i = 10, j = 2, k;
-
ary[0] = &i;
-
ary[1] = &j;
-
for (k = 0;k < 2; k++)
-
printf("%dn", *ary[k]);
-
}
a) Compile time error
b) 10 2
c) Undefined behaviour
d) segmentation fault/code crash
Answer: a
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
foo(ary);
-
}
-
void foo(int **ary)
-
{
-
int i = 10, k = 10, j = 2;
-
int *ary[2];
-
ary[0] = &i;
-
ary[1] = &j;
-
printf("%dn", ary[0][1]);
-
}
a) 10
b) 2
c) Compile time error
d) Undefined behaviour
Answer: d
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int ary[2][3][4], j = 20;
-
ary[0][0] = &j;
-
printf("%dn", *ary[0][0]);
-
}
a) Compile time error
b) 20
c) Address of j
d) Undefined behaviour
Answer: a
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int ary[2][3];
-
ary[][] = {{1, 2, 3}, {4, 5, 6}};
-
printf("%dn", ary[1][0]);
-
}
a) Compile time error
b) 4
c) 1
d) 2
Answer: a
Clarification: None.