ExamVeda
Login
Home
This question belongs to C Program Function
Function
?

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)); 
}

Answer & Solution
Correct Answer: Option C

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

Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Prerna Sharma
Prerna Sharma 4 years 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?
Mahipat Singh
Mahipat Singh 5 years ago
can anyone explain me this queiton