C Programming Questions and Answers – Initialization of Pointer Arrays – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Initialization of Pointer Arrays – 1”.

Pre-requisite for C Pointer Arrays Initialization MCQ set: Video Tutorial on C Pointers.

advertisement

1. Which of the following is the correct syntax to declare a 3 dimensional array using pointers?
a) char *a[][];
b) char **a[];
c) char ***a;
d) all of the mentioned
View Answer

Answer: a
Explanation: None.

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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *a = {"p", "r", "o", "g", "r", "a", "m"};
  5.         printf("%s", a);
  6.     }

a) Output will be program
b) Output will be p
c) No output
d) Compile-time error
View Answer

Answer: b
Explanation: None.
advertisement

3. An array of strings can be initialized by _________
a) char *a[] = {“Hello”, “World”};
b) char *a[] = {“Hello”, “Worlds”};
c)

char *b = "Hello";
char *c = "World";
char *a[] = {b, c};

d) all of the mentioned
View Answer

Answer: d
Explanation: None.
advertisement

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

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

a) segmentation fault
b) hi hello how followed by 7 null values
c) 10 null values
d) depends on compiler
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] = {"hi", "hello", "how"};
  5.         int i = 0, j = 0;
  6.         a[0] = "hey";
  7.         for (i = 0;i < 10; i++)
  8.         printf("%s\n", a[i]);
  9.     }

a) hi hello how Segmentation fault
b) hi hello how followed by 7 null values
c) hey hello how Segmentation fault
d) depends on compiler
View Answer

Answer: c
Explanation: None.

6. What will be the output of the following C code on a 32-bit system?

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

a) 10
b) 13
c) Run time error
d) 40
View Answer

Answer: d
Explanation: If the system is 32-bit system, then the size of pointer will be 4 bytes. For such a system, the size of array a will be 4×10 = 40 bytes. The size of pointer is 8 bytes on a 64 bit system. For the given array a of 10 elements, it will be 8×10 = 80 bytes.

7. What will be the output of the following C code on a 32-bit system?

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

a) 6
b) 4
c) 5
d) 3
View Answer

Answer: b
Explanation: Array element a[1] is storing an address of character pointer. For a 32-bit systems its 4 bytes and for a 64-bit system, its 8 bytes.

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

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

a) hi hello how Segmentation fault
b) hi hello how null
c) hey hello how Segmentation fault
d) hi hello how followed by 7 nulls
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.