250+ TOP MCQs on Pointers and Arrays and Answers

C quiz on “Pointers and Arrays”. One shall practice these quizzes to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C quiz comes with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C quiz on “Pointers and Arrays” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int a[3] = {1, 2, 3};
  5.         int *p = a;
  6.         printf("%pt%p", p, a);
  7.     }

a) Same address is printed
b) Different address is printed
c) Compile time error
d) Nothing
Answer: a
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *p = s;
  6.         printf("%pt%p", p, s);
  7.     }

a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing
Answer: b
Clarification: None.

3. What will be the output of the following C code?

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

a) Run time error
b) h h
c) h e
d) h l
Answer: c
Clarification: None.

4. What will be the output of the following C code?

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

a) h e
b) l l
c) l o
d) l e
Answer: d
Clarification: None.

5. What will be the output of the following C code?

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

a) h h
b) Run time error
c) l l
d) e e
Answer: d
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     void foo( int[] );
  3.     int main()
  4.     {
  5.         int ary[4] = {1, 2, 3, 4};
  6.         foo(ary);
  7.         printf("%d ", ary[0]);
  8.     }
  9.     void foo(int p[4])
  10.     {
  11.         int i = 10;
  12.         p = &i;
  13.         printf("%d ", p[0]);
  14.     }

a) 10 10
b) Compile time error
c) 10 1
d) Undefined behaviour
Answer: c
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         int *p = ary + 3;
  6.         printf("%dn", p[-2]);
  7.     }

a) 1
b) 2
c) Compile time error
d) Some garbage value
Answer: b
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         int *p = ary + 3;
  6.         printf("%d %dn", p[-2], ary[*p]);
  7.     }

a) 2 3
b) Compile time error
c) 2 4
d) 2 somegarbagevalue
Answer: d
Clarification: None.

Leave a Reply

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