C Programming - Functions

6. 

Usually recursion works slower than loops.

A. Yes
B. No

Answer: Option A

Explanation:

When a recursive call is made, the function/process clones itself and then process that funtion. This leads to time and space constrains.

In a loop, there is no recursive call involved that saves a lot of time and space too.


7. 

Is it true that too many recursive calls may result into stack overflow?

A. Yes
B. No

Answer: Option A

Explanation:

Yes, too many recursive calls may result into stack overflow. because when a function is called its return address is stored in stack.

After sometime the stack memory will be filled completely. Hence stack overflow error will occur.


8. 

In a function two return statements should never occur.

A. Yes
B. No

Answer: Option B

Explanation:

No, In a function two return statements can occur but not successively.

Example:


#include <stdio.h>
int mul(int, int); /* Function prototype */

int main()
{
    int a = 0, b = 3, c;
    c = mul(a, b);
    printf("c = %d\n", c);
    return 0;
}

/* Two return statements in the mul() function */
int mul(int a, int b)
{
   if(a == 0 || b == 0)
   {
        return 0;
   }
   else
   {
        return (a * b);
   }
}

Output:
c = 0


« Prev   1 2