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.
Anu said:
2 decades ago
I too think sree is right... but yes.. we need a more elaborate explanation... pls...
Nikunj said:
2 decades 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:
2 decades ago
Sree is absolutely right. Nice one. Good logic.
Sumit Pankaj said:
2 decades ago
Please explain once more
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