C Programming Questions and Answers – Basics of Functions – 2

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Basics of Functions – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         void foo();
  5.         printf("1 ");
  6.         foo();
  7.     }
  8.     void foo()
  9.     {
  10.         printf("2 ");
  11.     }

a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler
View Answer

Answer: a
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.     int main()
  3.     {
  4.         void foo(), f();
  5.         f();
  6.     }
  7.     void foo()
  8.     {
  9.         printf("2 ");
  10.     }
  11.     void f()
  12.     {
  13.         printf("1 ");
  14.         foo();
  15.     }

a) Compile time error as foo is local to main
b) 1 2
c) 2 1
d) Compile time error due to declaration of functions inside main
View Answer

Answer: b
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         void foo();
  5.         void f()
  6.         {
  7.             foo();
  8.         }
  9.         f();
  10.     }
  11.     void foo()
  12.     {
  13.         printf("2 ");
  14.     }

a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler
View Answer

Answer: d
Explanation: Even though the answer is 2, this code will compile fine only with gcc. GNU C supports nesting of functions in C as a language extension whereas standard C compiler doesn’t.
advertisement

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

  1.     #include <stdio.h>
  2.     void foo();
  3.     int main()
  4.     {
  5.         void foo();
  6.         foo();
  7.         return 0;
  8.     }
  9.     void foo()
  10.     {
  11.         printf("2 ");
  12.     }

a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void foo();
  3.     int main()
  4.     {
  5.         void foo(int);
  6.         foo(1);
  7.         return 0;
  8.     }
  9.     void foo(int i)
  10.     {
  11.         printf("2 ");
  12.     }

a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void foo();
  3.     int main()
  4.     {
  5.         void foo(int);
  6.         foo();
  7.         return 0;
  8.     }
  9.     void foo()
  10.     {
  11.         printf("2 ");
  12.     }

a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void m()
  3.     {
  4.         printf("hi");
  5.     }
  6.     void main()
  7.     {
  8.         m();
  9.     }

a) hi
b) Run time error
c) Nothing
d) Varies
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void m();
  3.     void n()
  4.     {
  5.         m();
  6.     }
  7.     void main()
  8.     {
  9.         void m()
  10.         {
  11.             printf("hi");
  12.         }
  13.     }

a) hi
b) Compile time error
c) Nothing
d) Varies
View Answer

Answer: b
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.