C Programming Questions and Answers on Basics of Functions for Freshers

1. What is the output of this 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
2. What is the output of this 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
3. What is the output of this 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

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 where as standard C compiler doesn’t.
4. What is the output of this 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
5. What is the output of this 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
6. What is the output of this 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
7. What is the output of this 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
Answer: a
8. What is the output of this 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
9. What is the output of this C code?

  1.     #include 
  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
Answer: b
10. What is the output of this C code?

  1.     #include 
  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
Answer: c
11. What is the output of this C code?

  1.     #include 
  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
Answer: d
12. 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
Answer: a
13. 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
Answer: d
14. 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
Answer: b
15. 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
Answer: c
16. The value obtained in the function is given back to main by using ________ keyword?

a) return
b) static
c) new
d) volatile
Answer: a

Related

Java Multiple Choice Questions & Answers on Inheritance for Freshers

1. Which of these keyword must be used to inherit a class? a) superb) thisc) extentd) extends Answer: d 2. Which of these keywords is used to refer to member of base class from a sub class? a) u...

HTML Multiple Choice Questions & Answers on Client-Side Graphics with Canvas for Freshers

1. Which of the following element is used for canvas graphics? a) b) <canvas> c) d) Answer: b Explanation: The HTML canvas element is used to draw graphics, on the fly, v...

CSS Multiple Choice Questions & Answers on Media Types for Freshers

1. What does all media type is used for? a) For use with all devicesb) For use with speech synthesizersc) For use with handheld devicesd) For use with tactile Braille devices Answer: a 2. What do...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item