C Programming - Functions - Discussion
Discussion Forum : Functions - Find Output of Program (Q.No. 5)
5.
What will be the output of the program?
#include<stdio.h>
void fun(int);
typedef int (*pf) (int, int);
int proc(pf, int, int);
int main()
{
int a=3;
fun(a);
return 0;
}
void fun(int n)
{
if(n > 0)
{
fun(--n);
printf("%d,", n);
fun(--n);
}
}
Discussion:
96 comments Page 8 of 10.
Nikunj said:
1 decade ago
Really good efforts.
I understood the concept of stack but please expand it more for better understanding!
I understood the concept of stack but please expand it more for better understanding!
Rakesh said:
1 decade ago
Sree is absolutely right. Nice one. Good logic.
Sumit Pankaj said:
1 decade ago
Please explain once more
Anusha said:
1 decade ago
@SREE:.
How can it execute the printf statement when the condition in if goes false at step 5. Can you explain please.
How can it execute the printf statement when the condition in if goes false at step 5. Can you explain please.
Divyasree said:
1 decade ago
Its very confusing Rithesh. I can't able to undstand the flow of excecution. Can anyone explain it clearly?
ABHI_027 said:
1 decade ago
How can it be printed as recursive function is executed repeatedly calling & at last the program is ended with false statements?
VIK said:
1 decade ago
PRINT(n=0), PRINT(n=1), PRINT(n=2), PRINT(n=0).
Arnab said:
1 decade ago
You can arrange each function call in a block and then understand it becomes easy,
As fun(3)---->fun(2)----------->
printf(2)
fun(1)
//After encountering parentheses return to the next line of the calling function.
As fun(3)---->fun(2)----------->
printf(2)
fun(1)
//After encountering parentheses return to the next line of the calling function.
Shafeeq said:
1 decade ago
Any simple method to find output of function with recursion?
Rishabh said:
1 decade ago
In step 5 the condition of if gets failed. Means it doesn't enter in its body. So how the output will generate?
Please explain.
Please explain.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers