250+ TOP MCQs on Initialization of Pointer Arrays and Answers

C helps anyone preparing for Ericsson and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear Ericsson interviews on C Programming language.

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?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *p[1] = {"hello"};
  5.         printf("%s", (p)[0]);
  6.         return 0;
  7.     }

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?

  1.     #include 
  2.     int main()
  3.     {
  4.         char **p = {"hello", "hi", "bye"};
  5.         printf("%s", (p)[0]);
  6.         return 0;
  7.     }

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?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0, j = 1;
  5.         int *a[] = {&i, &j};
  6.         printf("%d", (*a)[0]);
  7.         return 0;
  8.     }

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?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0, j = 1;
  5.         int *a[] = {&i, &j};
  6.         printf("%d", *a[0]);
  7.         return 0;
  8.     }

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?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0, j = 1;
  5.         int *a[] = {&i, &j};
  6.         printf("%d", (*a)[1]);
  7.         return 0;
  8.     }

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.

Leave a Reply

Your email address will not be published. Required fields are marked *