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

«
»

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

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

advertisement

1. What will be the output of the following C code (considering sizeof char is 1 and pointer is 4)?

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

a) 9
b) 4
c) 8
d) 10
View Answer

Answer: c
Explanation: None.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

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

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

a) 9
b) 12
c) 8
d) 10
View Answer

Answer: b
Explanation: None.
advertisement

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

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

a) hello
b) hi
c) ello
d) ello hi
View Answer

Answer: c
Explanation: None.
advertisement

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

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

a) hello
b) ello
c) hi
d) ello hi
View Answer

Answer: c
Explanation: None.

5. What is the advantage of a multidimensional array over pointer array?
a) Predefined size
b) Input can be taken from user
c) Faster Access
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

6. Which of the following operation is possible using a pointer char? (Assuming the declaration is char *a;)
a) Input via %s
b) Generation of the multidimensional array
c) Changing address to point at another location
d) All of the mentioned
View Answer

Answer: c
Explanation: None.

7. Comment on the following two operations.

    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2

a) 1 will work, 2 will not
b) 1 and 2, both will work
c) 1 won’t work, 2 will work
d) Neither of them will work
View Answer

Answer: c
Explanation: None.

8. Comment on the following two operations.

    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2

a) 1 works, 2 doesn’t
b) 2 works, 1 doesn’t
c) Both of them work
d) Neither of them work
View Answer

Answer: d
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

Leave a Comment

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 & technical discussions at Telegram SanfoundryClasses.