C MCQ set number 00675

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

Answer: a [Reason:] None.

2. Applications of multidimensional array are?
a) Matrix-Multiplication
b) Minimum Spanning Tree
c) Finding connectivity between nodes
d) All of the mentioned

Answer

Answer: d [Reason:] None.

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int ary[2][3];
  5.         foo(ary);
  6.     }
  7.     void foo(int *ary[])
  8.     {
  9.         int i = 10, j = 2, k;
  10.         ary[0] = &i;
  11.         ary[1] = &j;
  12.         *ary[0] = 2;
  13.         for (k = 0;k < 2; k++)
  14.         printf("%dn", *ary[k]);
  15.     }

a) 2 2
b) Compile time error
c) Undefined behaviour
d) 10 2

Answer

Answer: a [Reason:] None.

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int ary[2][3];
  5.         foo(ary);
  6.     }
  7.     void foo(int (*ary)[3])
  8.     {
  9.         int i = 10, j = 2, k;
  10.         ary[0] = &i;
  11.         ary[1] = &j;
  12.         for (k = 0;k < 2; k++)
  13.         printf("%dn", *ary[k]);
  14.     }

a) Compile time error
b) 10 2
c) Undefined behaviour
d) segmentation fault/code crash

Answer

Answer: a [Reason:] None.

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         foo(ary);
  5.     }
  6.     void foo(int **ary)
  7.     {
  8.         int i = 10, k = 10, j = 2;
  9.         int *ary[2];
  10.         ary[0] = &i;
  11.         ary[1] = &j;
  12.         printf("%dn", ary[0][1]);
  13.     }

a) 10
b) 2
c) Compile time error
d) Undefined behaviour

Answer

Answer: d [Reason:] None.

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int ary[2][3][4], j = 20;
  5.         ary[0][0] = &j;
  6.         printf("%dn", *ary[0][0]);
  7.     }

a) Compile time error
b) 20
c) Address of j
d) Undefined behaviour

Answer

Answer: a [Reason:] None.

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int ary[2][3];
  5.         ary[][] = {{1, 2, 3}, {4, 5, 6}};
  6.         printf("%dn", ary[1][0]);
  7.     }

a) Compile time error
b) 4
c) 1
d) 2

Answer

Answer: a [Reason:] None.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.