250+ TOP MCQs on Structures and Functions and Answers

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

Here is a listing of C Objective Questions on “Structures and Functions” 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.     int main()
  8.     {
  9.         struct point p = {1};
  10.         struct point p1 = {1};
  11.         if(p == p1)
  12.             printf("equaln");
  13.         else
  14.             printf("not equaln");
  15.     }

a) Compile time error
b) equal
c) depends on the standard
d) not equal
Answer: a
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.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     struct point foo();
  13.     int main()
  14.     {
  15.         struct point p = {1};
  16.         struct notpoint p1 = {2, 3};
  17.         p1 = foo();
  18.         printf("%dn", p1.x);
  19.     }
  20.     struct point foo()
  21.     {
  22.         struct point temp = {1, 2};
  23.         return temp;
  24.     }

a) Compile time error
b) 1
c) 2
d) Undefined behaviour
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.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     int main()
  13.     {
  14.         struct point p = {1};
  15.         struct notpoint p1 = p;
  16.         printf("%dn", p1.x);
  17.     }

a) Compile time error
b) 1
c) 0
d) Undefined
Answer: a
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.     };
  7.     struct notpoint
  8.     {
  9.         int x;
  10.         int y;
  11.     };
  12.     void foo(struct point);
  13.     int main()
  14.     {
  15.         struct notpoint p1 = {1, 2};
  16.         foo(p1);
  17.     }
  18.     void foo(struct point p)
  19.     {
  20.         printf("%dn", p.x);
  21.     }

a) Compile time error
b) 1
c) 0
d) Undefined
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};
  11.         foo(&p1);
  12.     }
  13.     void foo(struct point *p)
  14.     {
  15.         printf("%dn", *p.x++);
  16.     }

a) Compile time error
b) Segmentation fault/code crash
c) 2
d) 1
Answer: a
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};
  11.         foo(&p1);
  12.     }
  13.     void foo(struct point *p)
  14.     {
  15.         printf("%dn", *p->x++);
  16.     }

a) Compile time error
b) 1
c) Segmentation fault/code crash
d) 2
Answer: a
Clarification: None.

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

  1.     #include 
  2.     struct student fun(void)
  3.     {
  4.         struct student
  5.         {
  6.             char *name;
  7.         };
  8.         struct student s;
  9.         s.name = "alan";
  10.         return s;
  11.     }
  12.     void main()
  13.     {
  14.         struct student m = fun();
  15.         printf("%s", m.name);
  16.     }

a) Compile time error
b) alan
c) Nothing
d) Varies
Answer: a
Clarification: None.

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

  1.     #include 
  2.     struct student
  3.     {
  4.         char *name;
  5.     };
  6.     struct student fun(void)
  7.     {
  8.         struct student s;
  9.         s.name = "alan";
  10.         return s;
  11.     }
  12.     void main()
  13.     {
  14.         struct student m = fun();
  15.         printf("%s", m.name);
  16.     }

a) Nothing
b) alan
c) Run time error
d) Varies
Answer: b
Clarification: None.

  250+ TOP MCQs on Character Class Testing & Conversions and Answers

Leave a Comment

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

Scroll to Top