Here is a listing of C multiple choice questions on “Multidimensional Arrays” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int a[2][3] = {1, 2, 3, 4, 5};
-
int i = 0, j = 0;
-
for (i = 0; i < 2; i++)
-
for (j = 0; j < 3; j++)
-
printf("%d", a[i][j]);
-
}
a) 1 2 3 4 5 0
b) 1 2 3 4 5 junk
c) 1 2 3 4 5 5
d) Run time error
Answer: a
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int a[2][3] = {1, 2, 3, , 4, 5};
-
int i = 0, j = 0;
-
for (i = 0; i < 2; i++)
-
for (j = 0; j < 3; j++)
-
printf("%d", a[i][j]);
-
}
a) 1 2 3 junk 4 5
b) Compile time error
c) 1 2 3 0 4 5
d) 1 2 3 3 4 5
Answer: b
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
void f(int a[][3])
-
{
-
a[0][1] = 3;
-
int i = 0, j = 0;
-
for (i = 0; i < 2; i++)
-
for (j = 0; j < 3; j++)
-
printf("%d", a[i][j]);
-
}
-
void main()
-
{
-
int a[2][3] = {0};
-
f(a);
-
}
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
Answer: a
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
void f(int a[][])
-
{
-
a[0][1] = 3;
-
int i = 0, j = 0;
-
for (i = 0;i < 2; i++)
-
for (j = 0;j < 3; j++)
-
printf("%d", a[i][j]);
-
}
-
void main()
-
{
-
int a[2][3] = {0};
-
f(a);
-
}
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
Answer: c
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
void f(int a[2][])
-
{
-
a[0][1] = 3;
-
int i = 0, j = 0;
-
for (i = 0;i < 2; i++)
-
for (j = 0;j < 3; j++)
-
printf("%d", a[i][j]);
-
}
-
void main()
-
{
-
int a[2][3] = {0};
-
f(a);
-
}
a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values
Answer: c
Clarification: None.
6. Comment on the following C statement.
int (*a)[7];
a) An array “a” of pointers
b) A pointer “a” to an array
c) A ragged array
d) None of the mentioned
Answer: b
Clarification: None.
7. Comment on the following 2 arrays with respect to P and Q.
-
int *a1[8];
-
int *(a2[8]);
-
P. Array of pointers
-
Q. Pointer to an array
a) a1 is P, a2 is Q
b) a1 is P, a2 is P
c) a1 is Q, a2 is P
d) a1 is Q, a2 is Q
Answer: b
Clarification: None.
8. Which of the following is not possible statically in C?
a) Jagged Array
b) Rectangular Array
c) Cuboidal Array
d) Multidimensional Array
Answer: a
Clarification: None.