C Programming Questions and Answers on Initialization of Pointer Arrays for Freshers

https://www.computersprofessor.com/2017/12/c-programming-questions-and-answers-on_21.html
1. To declare a 3 dimension array using pointers, which of the following is the correct syntax:
a) char *a[][];
b) char **a[];
c) char ***a;
d) all of the mentioned
Answer: a
2. Comment on the output of this C code?
#include
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
b) Output will be p
c) No output
d) Compile-time error
Answer: b
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
Answer: d
4. What is the output of this C code?
#include
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
b) hi hello how followed by 7 null values
c) 10 null values
d) depends on compiler
Answer: a
5. What is the output of this C code?
#include
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 Segmentation fault
d) depends on compiler
b) hi hello how followed by 7 null values
c) hey hello how Segmentation fault
d) depends on compiler
Answer: c
6. What is the output of this C code?
#include
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", sizeof(a));
}
a) 10
b) 13
c) Run time error
d) 40
b) 13
c) Run time error
d) 40
Answer: d
7. What is the output of this C code?
#include
void main()
{
char *a[10] = {"hi", "hello", "how"};
printf("%d\n", sizeof(a[1]));
}
a) 6
b) 4
c) 5
d) 3
b) 4
c) 5
d) 3
Answer: b
8. What is the output of this C code?
#include
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
b) hi hello how null
c) hey hello how Segmentation fault
d) hi hello how followed by 7 nulls
Answer: d
9. What is the output of this 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
b) Undefined behaviour
c) hello
d) None of the mentioned
Answer: c
10. What is the output of this 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
b) Undefined behaviour
c) hello
d) Address of hello
Answer: b
11. What is the output of this 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
b) Undefined behaviour
c) 0
d) Some garbage value
Answer: c
12. What is the output of this 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
b) Undefined behaviour
c) 0
d) Some garbage value
Answer: c
13. What is the output of this 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
b) Undefined behaviour
c) 1
d) Some garbage value
Answer: d
14. 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
15. 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