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 9 of 10.
Vishal said:
1 decade ago
Friends if we change the (--n) to (n--) after the printf statement
Then check the answer and explain it plz..........
Then check the answer and explain it plz..........
Sony said:
1 decade ago
Please explain it clearly.
Wikiok said:
1 decade ago
If the program returns from the first "fun(--n)" function it will continue running to printf statement, and then the other fun(--n) statement comes.
Shanmugapriya said:
1 decade ago
Please explain it in clear.
Anu said:
1 decade ago
I too think sree is right... but yes.. we need a more elaborate explanation... pls...
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.
Popat said:
1 decade ago
Its correct answer Thanks Sree
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers