250+ TOP MCQs on Basics of Functions and Answers

C Objective Questions on “Basics of Functions”. One shall practice these Objective 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 Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Basics of Functions” along with answers, explanations and/or solutions:

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

  1.     #include 
  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
Answer: a
Clarification: None.

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

  1.     #include 
  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
Answer: b
Clarification: None.

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

  1.     #include 
  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
Answer: d
Clarification: 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.

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

  1.     #include 
  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
Answer: b
Clarification: None.

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

  1.     #include 
  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
Answer: a
Clarification: None.

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

  1.     #include 
  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
Answer: b
Clarification: None.

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

  1.     #include 
  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
Answer: a
Clarification: None.

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

  1.     #include 
  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
Answer: b
Clarification: None.

  250+ TOP MCQs on Pointers and Arrays and Answers

Leave a Comment

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

Scroll to Top