C Programming Questions and Answers – Basics of Functions – 1

«
»

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

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

advertisement

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?

advertisement
  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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.