250+ TOP MCQs on Arrays of Structures and Answers

C helps anyone preparing for Philips and other companies C interviews on C Programming language.

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

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

  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1[]  =  {1, 2, 3, 4};
  11.         foo(p1);
  12.     }
  13.     void foo(struct point p[])
  14.     {
  15.         printf("%dn", p[1].x);
  16.     }

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

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

  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1[] = {1, 2, 3, 4};
  11.         foo(p1);
  12.     }
  13.     void foo(struct point p[])
  14.     {
  15.         printf("%dn", p->x);
  16.     }

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

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

  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1[] = {1, 2, 3, 4};
  11.         foo(p1);
  12.     }
  13.     void foo(struct point p[])
  14.     {
  15.         printf("%d %dn", p->x, ++p->x);
  16.     }

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

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

  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     } p[] = {1, 2, 3, 4, 5};
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         foo(p);
  11.     }
  12.     void foo(struct point p[])
  13.     {
  14.         printf("%d %dn", p->x, p[2].y);
  15.     }

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

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

  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1[] = {1, 2, 3, 4, 5};
  11.         foo(p1);
  12.     }
  13.     void foo(struct point p[])
  14.     {
  15.         printf("%d %dn", p->x, p[3].y);
  16.     }

a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) None of the mentioned
Answer: c
Clarification: None.

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

  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1[] = {1, 2, 3, 4, 5};
  11.         foo(p1);
  12.     }
  13.     void foo(struct point p[])
  14.     {
  15.         printf("%d %dn", p->x, (p + 2).y);
  16.     }

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

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

  1.     #include 
  2.     struct point
  3.     {
  4.         int x;
  5.         int y;
  6.     };
  7.     void foo(struct point*);
  8.     int main()
  9.     {
  10.         struct point p1[] = {1, 2, 3, 4, 5};
  11.         foo(p1);
  12.     }
  13.     void foo(struct point p[])
  14.     {
  15.         printf("%d %dn", p->x, (p + 2)->y);
  16.     }

a) Compile time error
b) 1 0
c) 1 somegarbagevalue
d) undefined behaviour
Answer: b
Clarification: None.

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

  1.     #include 
  2.     struct student
  3.     {
  4.         char *c;
  5.     };
  6.     void main()
  7.     {
  8.         struct student s[2];
  9.         printf("%d", sizeof(s));
  10.     }

a) 2
b) 4
c) 16
d) 8
Answer: d
Clarification: None.

Leave a Reply

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