C Programming Questions and Answers – Complicated Declarations – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Complicated Declarations – 1”.

Pre-requisite for C Complicated Declarations MCQ set: Video Tutorial on C Pointers.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

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

Note: Join free Sanfoundry classes at Telegram or Youtube
  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int *((*x)())[2];
  5.         x();
  6.         printf("after x\n");
  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
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  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 %f\n", i, f);
  18.     }

a) 1 2.000000
b) 1 2
c) Compile time error
d) Segmentation fault/code crash
View Answer

Answer: a
Explanation: None.

9. What does this declaration say?

int (*(*y)())[2];

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
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  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 %f\n", i, f);
  17.     }

a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  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 %f\n", i, f);
  17.     }

a) Compile time error
b) Undefined behaviour
c) 1 2.000000
d) Nothing
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.