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 4 of 10.
Vishal said:
1 decade ago
if(3>0) true.
step:1 fun(2).
if(2>0) true.
step:2 fun(1).
if(1>0) true.
step:3 fun(0).
if(0>0) false.
print 0 from step:3, fun(-1) false.
print 1 from step:2, fun(0) false.
print 2 from step:1, fun(1)->fun(0).
print 0 from fun (0) at second last line.
step:1 fun(2).
if(2>0) true.
step:2 fun(1).
if(1>0) true.
step:3 fun(0).
if(0>0) false.
print 0 from step:3, fun(-1) false.
print 1 from step:2, fun(0) false.
print 2 from step:1, fun(1)->fun(0).
print 0 from fun (0) at second last line.
Guddi said:
7 years ago
I don't understand. Please explain to me.
Subu said:
1 decade ago
Please explain this.
Kavita said:
1 decade ago
Thanks Sree.
Lakshmi said:
1 decade ago
Sree i didnt get wat u r saying.Plz can u explain me in brief.
Fuad Al Masud said:
7 years ago
Can anyone explain the program in detail?
Tejashri said:
7 years ago
Hi, please explain this program in simple way.
Bagesh kumar bagi said:
1 decade ago
Any one explain again?
VInith kumar said:
7 years ago
Simply great @Mukunda Saini.
Rajarshi said:
7 years ago
Here, we can Apply the concept of recursive tree.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers