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.

advertisement

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

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

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

Answer: b
Explanation: None.
advertisement
advertisement

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

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

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

Answer: c
Explanation: None.
advertisement

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

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

a) Run time error
b) hi
c) Infinite hi
d) hi hi
View Answer

Answer: d
Explanation: None.
advertisement

4. Which of the following is a correct format for declaration of function?
a) return-type function-name(argument type);
b) return-type function-name(argument type){}
c) return-type (argument type)function-name;
d) all of the mentioned
View Answer

Answer: a
Explanation: None.

5. Which of the following function declaration is illegal?
a) int 1bhk(int);
b) int 1bhk(int a);
c) int 2bhk(int*, int []);
d) all of the mentioned
View Answer

Answer: d
Explanation: None.

6. Which function definition will run correctly?
a)

   int sum(int a, int b)
   return (a + b);

b)

   int sum(int a, int b)
   {return (a + b);}

c)

   int sum(a, b)
   return (a + b);

d) none of the mentioned
View Answer

Answer: b
Explanation: None.

7. Can we use a function as a parameter of another function? [Eg: void wow(int func())].
a) Yes, and we can use the function value conveniently
b) Yes, but we call the function again to get the value, not as convenient as in using variable
c) No, C does not support it
d) This case is compiler dependent
View Answer

Answer: c
Explanation: None.

8. The value obtained in the function is given back to main by using ________ keyword.
a) return
b) static
c) new
d) volatile
View Answer

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