This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Initialization of Pointer Arrays – 2”.
Pre-requisite for C Pointer Arrays Initialization MCQ set: Video Tutorial on C Pointers.
1. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *p[1] = {"hello"};
printf("%s", (p)[0]);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) hello
d) None of the mentioned
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char **p = {"hello", "hi", "bye"};
printf("%s", (p)[0]);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) hello
d) Address of hello
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0, j = 1;
int *a[] = {&i, &j};
printf("%d", (*a)[0]);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) 0
d) Some garbage value
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0, j = 1;
int *a[] = {&i, &j};
printf("%d", *a[0]);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) 0
d) Some garbage value
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 0, j = 1;
int *a[] = {&i, &j};
printf("%d", (*a)[1]);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) 1
d) Some garbage value
View Answer
Explanation: None.
6. Which of the following are generated from char pointer?
a) char *string = “Hello.”;
b)
char *string; scanf("%s", string);
c) char string[] = “Hello.”;
d) char *string = “Hello.”; and char string[] = “Hello.”;
View Answer
Explanation: None.
7. Which of the following declaration are illegal?
a) int a[][] = {{1, 2, 3}, {2, 3, 4, 5}};
b) int *a[] = {{1, 2, 3}, {2, 3, 4, 5}};
c) int a[4][4] = {{1, 2, 3}, {2, 3, 4, 5}};
d) none of the mentioned
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.
- Practice Computer Science MCQs
- Practice BCA MCQs
- Watch Advanced C Programming Videos
- Apply for Computer Science Internship
- Apply for C Internship