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));
}
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.
Join The Discussion
Comments ( 2 )
Related Questions on Function
In C, what is a function primarily used for?
A. Decision making
B. Variable declaration
C. Code organization and reusability
D. Printing output
What is the purpose of a function prototype in C?
A. To declare a function's return type
B. To declare a function's name
C. To declare a function's parameters and return type
D. To declare a function's name and parameters
In C, how are function arguments passed by default?
A. By value
B. By reference
C. By pointer
D. By address
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?
can anyone explain me this queiton