C Functions-3
1.It is necessary to declare the type of a function in the calling program if the function
a) Return an integer
b) Returns a non-integer value
c) is not defined in the same file
d) None of these
Answer: B
No explanation is given for this question.
2. What will be the value returned by the following function, when it is called with a value 11?
recur(int num() {
if((2) != 0 )
return(recur(2) * 10+num% %2)
else
return 1;
}
a) Function does not return any value, because it goes into an infinite loop
b) 11
c) 1011
d) None of these
Answer: C
No explanation is given for this question.
3. The function that actually created from a call to a template function is called
a) Generated
b) Inherited
c) Spawned
d) Declassified
Answer: C
No explanation is given for this question.
4. The function fprintf is used in a program.
a) When too many printf calls have been alrady used in the program
b) In place of printf, since printf uses more memory
c) When output i to be printed on to a file
d) All of above
Answer: C
No explanation is given for this question.
5. What is the output of C program with pointers.
int main() {
int a = 20;
//a memory location = 1234
printf("%d %d %d %d", a, &a, *(&a));
return 0;
}
a) 20 20 20
b) 20 1234 1234
c) 20 1234 20
d) 20 20 20
Answer: C
If * VALUEAT operator and & ADDRESSOF operator are used immediately, it is same as the variable itself. So *(&a) == a.
6. What is the output of C program with functions?
int main() {
int a = 20;
printf("CINEMA ");
return 1;
printf("DINOSAUR ");
return 1;
}
a) CINEMA DINOSAUR
b) CINEMA
c) DINOSAUR
d) Compiler error
Answer: B
There are two return statements in main() function. Only first return is executed. All the statements or lines of code below first return is not reachable and hence not executed.
7. What is the output of C program with recursive function?
int sum(int x) {
int k = 1
if(x <= 1)
return 1;
k = x + sum(x - 1);
return k;
}
a) 10
b) 11
c) 12
d) 15
Answer: A
4 + 3 + 2 + 1 = 10
8. A recursive function can be replaced with __ in C language.
a) for loop
b) while loop
c) do while loop
d) All the above
Answer: D
No explaination is given for this question.
9. A recursive function is faster than __ loop.
a) for
b) while
c) do while
d) None of the above
Answer: D
Yes. Recursion is slow. Variable are kept and remove on STACK memory multiple times.
10. What is the C keyword that must be used to achieve expected result using Recursion?
a) printf
b) scanf
c) void
d) return
Answer: D
Recursion is entirely based on RETURN value statement.