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.
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
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *a = {"p", "r", "o", "g", "r", "a", "m"};
printf("%s", a);
}
a) Output will be program
b) Output will be p
c) No output
d) Compile-time error
View Answer
Explanation: None.
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
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
int i = 0;
for (i = 0;i < 10; i++)
printf("%s", *(a[i]));
}
a) segmentation fault
b) hi hello how followed by 7 null values
c) 10 null values
d) depends on compiler
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
int i = 0, j = 0;
a[0] = "hey";
for (i = 0;i < 10; i++)
printf("%s\n", a[i]);
}
a) hi hello how Segmentation fault
b) hi hello how followed by 7 null values
c) hey hello how followed by 7 null values
d) hey hello how Segmentation fault
View Answer
Explanation: None.
6. What will be the output of the following C code on a 32-bit system?
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", sizeof(a));
}
a) 10
b) 13
c) Run time error
d) 40
View Answer
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?
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", sizeof(a[1]));
}
a) 6
b) 4
c) 5
d) 3
View Answer
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?
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
int i = 0;
for (i = 0;i < 10; i++)
printf("%s", a[i]);
}
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
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.
- Check Computer Science Books
- Practice BCA MCQs
- Apply for C Internship
- Check C Books
- Watch Advanced C Programming Videos