C Programming Questions and Answers on Functions Returning Non-integers for Freshers

1. What is the return-type of the function sqrt()

a) int
b) float
c) double
d) depends on the data type of the parameter
Answer: c
2. Which of the following function declaration is illegal?

a) double func();
    int main(){}
    double func(){}
b) double func(){};
    int main(){}
c) int main()
    {
    double func();
    }
    double func(){//statements}
d) None of the mentioned
Answer: d
3. What is the output of this code having void return-type function?

  1.     #include 
  2.     void foo()
  3.     {
  4.         return 1;
  5.     }
  6.     void main()
  7.     {
  8.         int x = 0;
  9.         x = foo();
  10.         printf("%d", x);
  11.     }
a) 1
b) 0
c) Runtime error
d) Compile time error
Answer: d
4. What will be the data type returned for the following function?

  1.     #include 
  2.     int func()
  3.     {
  4.         return (double)(char)5.0;
  5.     }
a) char
b) int
c) double
d) multiple type-casting in return is illegal
Answer: b
5. What is the problem in the following declarations?
    int func(int);
    double func(int);
    int func(float);

a) A function with same name cannot have different signatures
b) A function with same name cannot have different return types
c) A function with same name cannot have different number of parameters
d) All of the mentioned
Answer: d
6. The output of the code below is

  1.     #include 
  2.     void main()
  3.     {
  4.         int k = m();
  5.         printf("%d", k);
  6.     }
  7.     void m()
  8.     {
  9.         printf("hello");
  10.     }
a) hello 5
b) Error
c) Nothing
d) Junk value
Answer: a
7. The output of the code below is

  1.     #include 
  2.     int *m()
  3.     {
  4.         int *p = 5;
  5.         return p;
  6.     }
  7.     void main()
  8.     {
  9.         int *k = m();
  10.         printf("%d", k);
  11.     }
a) 5
b) Junk value
c) 0
d) Error
Answer: a
8. The output of the code below is

  1.     #include 
  2.     int *m();
  3.     void main()
  4.     {
  5.         int *k = m();
  6.         printf("hello ");
  7.         printf("%d", k[0]);
  8.     }
  9.     int *m()
  10.     {
  11.         int a[2] = {5, 8};
  12.         return a;
  13.     }
a) hello 5 8
b) hello 5
c) hello followed by garbage value
d) Compilation error
Answer: c
9. The output of the code below is

  1.     #include 
  2.     int *m();
  3.     void main()
  4.     {
  5.         int k = m();
  6.         printf("%d", k);
  7.     }
  8.     int *m()
  9.     {
  10.         int a[2] = {5, 8};
  11.         return a;
  12.     }
a) 5
b) 8
c) Nothing
d) Varies
Answer: d
10. The output of the code below is

  1.     #include 
  2.     void m(int k)
  3.     {
  4.         printf("hi");
  5.     }
  6.     void m(double k)
  7.     {
  8.         printf("hello");
  9.     }
  10.     void main()
  11.     {
  12.         m(3);
  13.     }
a) hi
b) hello
c) Compile time error
d) Nothing
Answer: c
11. What is the default return type if it is not specified in function definition?

a) void
b) int
c) double
d) short int
Answer: b
12. What is the output of this C code?

  1.     #include 
  2.     int foo();
  3.     int main()
  4.     {
  5.         int i = foo();
  6.     }
  7.     foo()
  8.     {
  9.         printf("2 ");
  10.         return 2;
  11.     }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: a
13. What is the output of this C code?

  1.     #include 
  2.     double foo();
  3.     int main()
  4.     {
  5.         foo();
  6.         return 0;
  7.     }
  8.     foo()
  9.     {
  10.         printf("2 ");
  11.         return 2;
  12.     }
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: b
14. functions can return structure in c?

a) true
b) false
c) Depends on the compiler
d) Depends on the standard
Answer: a
15. functions can return enumeration constants in c?

a) true
b) false
c) depends on the compiler
d) depends on the standard
Answer: a
16. What is the output of code given below?

  1.     #include 
  2.     enum m{JAN, FEB, MAR};
  3.     enum m foo();
  4.     int main()
  5.     {
  6.         enum m i = foo();
  7.         printf("%d\n", i);
  8.     }
  9.     int  foo()
  10.     {
  11.         return JAN;
  12.     }
a) Compile time error
b) 0
c) Depends on the compiler
d) Depends on the standard
Answer: a

Related

C# Questions & Answers on Polymorphism for Freshers

1. The capability of an object in Csharp to take number of different forms and hence display behaviour as according is known as: a) Encapsulationb) Polymorphismc) Abstractiond) None of the mentione...

C# Questions & Answers on Use of Variable Number of Arguements for Freshers

1. The method in which large or variable number of arguments are handled is known as: a) Value parametersb) Output parametersc) Parameter arraysd) None of the mentioned Answer: c 2. The modifiers...

C# Questions & Answers on Use of Ref and Out Parameters for Freshers

1. What is output for the following code snippet? class Program { static void Main(string[] args) { int i = 5; int j; method1(ref i); m...

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