Here is a listing of tough C Objective Questions on “Initialization of Pointer Arrays” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
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
Answer: c
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
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
Answer: b
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
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
Answer: c
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
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
Answer: c
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
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
Answer: d
Clarification: 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.”;
Answer: a
Clarification: 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
Answer: a
Clarification: None.