Here is a listing of online C test questions on “Functions Returning Non-integers” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
int *m();
-
void main()
-
{
-
int k = m();
-
printf("%d", k);
-
}
-
int *m()
-
{
-
int a[2] = {5, 8};
-
return a;
-
}
a) 5
b) 8
c) Nothing
d) Varies
Answer: d
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
void m(int k)
-
{
-
printf("hi");
-
}
-
void m(double k)
-
{
-
printf("hello");
-
}
-
void main()
-
{
-
m(3);
-
}
a) hi
b) hello
c) Compile time error
d) Nothing
Answer: c
Clarification: None.
3. 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
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
int foo();
-
int main()
-
{
-
int i = foo();
-
}
-
foo()
-
{
-
printf("2 ");
-
return 2;
-
}
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: a
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
double foo();
-
int main()
-
{
-
foo();
-
return 0;
-
}
-
foo()
-
{
-
printf("2 ");
-
return 2;
-
}
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
Answer: b
Clarification: None.
6. Functions can return structure in C?
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
Answer: a
Clarification: None.
7. Functions can return enumeration constants in C?
a) true
b) false
c) depends on the compiler
d) depends on the standard
Answer: a
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
enum m{JAN, FEB, MAR};
-
enum m foo();
-
int main()
-
{
-
enum m i = foo();
-
printf("%dn", i);
-
}
-
int foo()
-
{
-
return JAN;
-
}
a) Compile time error
b) 0
c) Depends on the compiler
d) Depends on the standard
Answer: a
Clarification: None.