C Programming Questions and Answers – Pointers Vs. Multi-dimensional Arrays – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Pointers Vs. Multi-dimensional Arrays – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. Which is true for a, if a is defined as “int a[10][20];”?
a) a is true two-dimensional array
b) 200 int-sized locations have been set aside
c) The conventional rectangular subscript calculation 20 * row + col is used to find the element a[row, col].
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

2. Which is true for b, if b is defined as “int *b[10];”?
a) The definition only allocates 10 pointers and does not initialize them
b) Initialization must be done explicitly
c) The definition only allocates 10 pointers and does not initialize them & Initialization must be done explicitly
d) Error
View Answer

Answer: c
Explanation: None.
advertisement
advertisement

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char a[10][5] = {"hi", "hello", "fellows"};
  5.         printf("%s", a[2]);
  6.     }

a) fellows
b) fellow
c) fello
d) fell
View Answer

Answer: c
Explanation: Since every row in the array a[10][5] can contain only 5 characters, the a[2] element will hold “fello” i.e. 5 characters. There will not be any null character in a[2]. Since, the array is completely intialized, other rows (row a[3] will have only null characters. Hence, printf() using %s specifier will display fello only.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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

advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char a[10][5] = {"hi", "hello", "fellows"};
  5.         printf("%p\n", a);
  6.         printf("%p", a[0]);
  7.     }

a) same address is printed
b) different address is printed
c) hello
d) hi hello fello
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char a[10][5] = {"hi", "hello", "fellows"};
  5.         printf("%d", sizeof(a[1]));
  6.     }

a) 2
b) 4
c) 5
d) 10
View Answer

Answer: c
Explanation: None.

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

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

a) Compile time error
b) hello
c) Undefined behaviour
d) hellon
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *a[1] = {"hello"};
  5.         printf("%s", a[0]);
  6.         return 0;
  7.     }

a) Compile time error
b) hello
c) Undefined behaviour
d) hellon
View Answer

Answer: b
Explanation: None.

8. Which of the following statements are true?

    P. Pointer to Array
    Q. Multi-dimensional array

a) P are static, Q are static
b) P are static, Q are dynamic
c) P are dynamic, Q are static
d) P are dynamic, Q are dynamic
View Answer

Answer: c
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.