This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Functions Returning Non-integers – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
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
View Answer
Explanation: None.
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
View Answer
Explanation: None.
3. What will be the output of the following C code having void return-type function?
#include <stdio.h>
void foo()
{
return 1;
}
void main()
{
int x = 0;
x = foo();
printf("%d", x);
}
a) 1
b) 0
c) Runtime error
d) Compile time error
View Answer
Explanation: None.
4. What will be the data type returned for the following C function?
#include <stdio.h>
int func()
{
return (double)(char)5.0;
}
a) char
b) int
c) double
d) multiple type-casting in return is illegal
View Answer
Explanation: None.
5. What is the problem in the following C 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
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
int m()
{
printf("hello");
}
void main()
{
int k = m();
printf("%d", k);
}
a) hello5
b) Error
c) Nothing
d) Junk value
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
int *m()
{
int *p = 5;
return p;
}
void main()
{
int *k = m();
printf("%d", k);
}
a) 5
b) Junk value
c) 0
d) Error
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
int *m();
void main()
{
int *k = m();
printf("hello ");
printf("%d", k[0]);
}
int *m()
{
int a[2] = {5, 8};
return a;
}
a) hello 5 8
b) hello 5
c) hello followed by garbage value or runtime error
d) Compilation error
View Answer
Explanation: Since are returning the address of a local array variable ‘a’, the compiler will give a warning in most of the cases. However, the program will run, but it will result in unexpected behaviour. In most of the compilers, it will result in a core dump due to segmentation fault whereas in some compilers, it might print hello followed by garbage value.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Computer Science Internship
- Practice BCA MCQs
- Check Computer Science Books
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos