Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Multidimensional Arrays

C Programming Questions and Answers – Multidimensional Arrays

1.What is the output of this C code?

 

#include <stdio.h>

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

“View

 

Answer:a

2.What is the output of this C code?

 

#include <stdio.h>

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

“View

Answer:b

 

3.What is the output of this C code?

#include <stdio.h>

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

“View

Answer:a

 

4.What is the output of this C code?

#include <stdio.h>

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

“View

Answer:c

 

5.What is the output of this C code?

#include <stdio.h>

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

“View

Answer:c

 

6.Comment on the following 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

“View

Answer:b

 

7.Comment on the 2 arrays regarding P and Q:

int *a1[8];

int *(a3[8]);

Array of pointers

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

“View

Answer:b

 

8.Which of the following is not possible statically in C?

a) Jagged Array

b) Rectangular Array

c) Cuboidal Array

d) Multidimensional Array

“View

Answer:a

 

9.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);

“View

 

Answer:a

Applications of multidimensional array are?

a) Matrix-Multiplication

b) Minimum Spanning Tree

c) Finding connectivity between nodes

d) All of the mentioned

“View

 

Answer:d

10.What is the output of this C code?

#include <stdio.h>

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(“%d\n”, *ary[k]);

}

a) 2 2

b) Compile time error

c) Undefined behaviour

d) 10 2

“View

Answer:a

 

11.What is the output of this C code?

#include <stdio.h>

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(“%d\n”, *ary[k]);

}

a) Compile time error

b) 10 2

c) Undefined behaviour

d) segmentation fault/code crash

“View

Answer:a

 

12.What is the output of this C code?

#include <stdio.h>

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(“%d\n”, ary[0][1]);

}

a) 10

b) 2

c) Compile time error

d) Undefined behaviour

“View

Answer:d

 

13.What is the output of this C code?

#include <stdio.h>

int main()

{

int ary[2][3][4], j = 20;

ary[0][0] = &j;

printf(“%d\n”, *ary[0][0]);

}

a) Compile time error

b) 20

c) Address of j

d) Undefined behaviour

“View

Answer:a

 

14.What is the output of this C code?

#include <stdio.h>

int main()

{

int ary[2][3];

ary[][] = {{1, 2, 3}, {4, 5, 6}};

printf(“%d\n”, ary[1][0]);

}

a) Compile time error

b) 4

c) 1

d) 2

“View

Answer:a

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button