250+ TOP MCQs on Complicated Declarations and Answers

C question bank on “Complicated Declarations”. One shall practice these questions 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 question bank comes with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C question bank on “Complicated Declarations” 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.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         no = 8;
  11.         printf("%d", no);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
Answer: b
Clarification: None.

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

  1.     #include 
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

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

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

  1.     #include 
  2.     struct student
  3.     {
  4.         int no = 5;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

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

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

  1.     #include 
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         student s;
  10.         s.name = "hello";
  11.         printf("hello");
  12.     }

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

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

  1.     #include 
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("%s", s.name);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
Answer: c
Clarification: None.

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

  1.     #include 
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     struct student s;
  8.     void main()
  9.     {
  10.         s.no = 8;
  11.         printf("%s", s.name);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int *((*x)())[2];
  5.         x();
  6.         printf("after xn");
  7.     }
  8.     int *((*x)())[2]
  9.     {
  10.         int **str;
  11.         str = (int*)malloc(sizeof(int)* 2);
  12.         return str;
  13.     }

a) Compile time error
b) Undefined behaviour
c) After x
d) None of the mentioned
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void (*(f)())(int, float);
  3.     void (*(*x)())(int, float) = f;
  4.     void ((*y)(int, float));
  5.     void foo(int i, float f);
  6.     int main()
  7.     {
  8.         y = x();
  9.         y(1, 2);
  10.     }
  11.     void (*(f)())(int, float)
  12.     {
  13.         return foo;
  14.     }
  15.     void foo(int i, float f)
  16.     {
  17.         printf("%d %fn", i, f);
  18.     }

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

9. What does this declaration say?

a) y is pointer to the function which returns pointer to integer array
b) y is pointer to the function which returns array of pointers
c) y is function which returns function pointer which in turn returns pointer to integer array
d) y is function which returns array of integers
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void (*(f)())(int, float);
  3.     typedef void (*(*x)())(int, float);
  4.     void foo(int i, float f);
  5.     int main()
  6.     {
  7.         x = f;
  8.         x();
  9.     }
  10.     void (*(f)())(int, float)
  11.     {
  12.         return foo;
  13.     }
  14.     void foo(int i, float f)
  15.     {
  16.         printf("%d %fn", i, f);
  17.     }

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

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

  1.     #include 
  2.     void (*(f)())(int, float);
  3.     typedef void (*(*x)())(int, float);
  4.     void foo(int i, float f);
  5.     int main()
  6.     {
  7.         x p = f;
  8.         p();
  9.     }
  10.     void (*(f)())(int, float)
  11.     {
  12.         return foo;
  13.     }
  14.     void foo(int i, float f)
  15.     {
  16.         printf("%d %fn", i, f);
  17.     }

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

Leave a Reply

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