Examveda
Examveda

What will be printed when this program is executed?
int f(int x)
{
   if(x <= 4)
      return x;
   return f(--x);
}
void main()
{
   printf("%d ", f(7)); 
}

A. 4 5 6 7

B. 1 2 3 4

C. 4

D. Syntax error

E. Runtime error

Answer: Option C

Solution(By Examveda Team)

In this recursive function call the function will return to main caller when the value of x is 4. Hence the output.


This Question Belongs to C Program >> Function

Join The Discussion

Comments ( 2 )

  1. Prerna Sharma
    Prerna Sharma :
    1 year ago

    I think its answer will printed 1 ,because if statement is wrong and compiler put by default value 1. So its answer will be printed 1.

    Can anyone say the correct answer?

  2. Mahipat Singh
    Mahipat Singh :
    3 years ago

    can anyone explain me this queiton

Related Questions on Function