C Programming Questions and Answers – Multidimensional Arrays – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Multidimensional Arrays – 2”.

Pre-requisite for C Multidimensional Arrays MCQ set: Video Tutorial on 3-Dimensional Arrays.

advertisement

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);
View Answer

Answer: a
Explanation: 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
View Answer

Answer: d
Explanation: None.
advertisement
advertisement

3. What will be the output of the following C code?

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

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

Answer: a
Explanation: None.
advertisement

4. What will be the output of the following C code?

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

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

Answer: a
Explanation: None.
advertisement

5. What will be the output of the following 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 = 20, j = 30;
  9.         int *ary[2];
  10.         ary[0] = &i;
  11.         ary[1] = &j;
  12.         printf("%d\n", ary[0][1]);
  13.     }

a) 10
b) 20
c) Compile time error
d) Undefined behaviour
View Answer

Answer: d
Explanation: None.

6. What will be the output of the following 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("%d\n", *ary[0][0]);
  7.     }

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

Answer: a
Explanation: None.

7. What will be the output of the following 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("%d\n", ary[1][0]);
  7.     }

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

Answer: a
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.