#include<stdio.h>
void fun(int);
int main()
{
int a;
a=3;
fun(a);
printf("\n");
return 0;
}
void fun(int i)
{
if(n>0)
{
fun(--n);
printf("%d",n);
fun(--n);
}
} the answer is 0 1 2 0..someone explain how the code is
executed..?






#include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"..

Answer / siva kumar

for example :
Here a is three(3).

calling fun(3) in main function.
FUN(3) {
calling fun(2) {
calling fun(1) {
calling fun(0) {
N>0 found.
}
printed 0
calling second fun(-1) {
N>0 found.
}
}
printed 1
calling second fun(0) {
N>0 found.
}
}
printed 2
calling second fun(1) {
calling fun(0) {
N>0 found.
}
printed 0
calling second fun(-1) {
N>0 found.
}
}
}

Is This Answer Correct ?    17 Yes 8 No

Post New Answer




More C Code Interview Questions

what is oop?

3 Answers  


C program to print magic square of order n where n > 3 and n is odd

2 Answers   Accenture,


main() { printf("%d", out); } int out=100;

3 Answers  


main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }

7 Answers  


how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!

8 Answers   GATE,






How to return multiple values from a function?

7 Answers  


Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024

2 Answers   HCL,


#include <stdio.h> int main(void) { int a=4, b=2; a=b<<a+b>>2 ; printf("%d",a); return 0; }

0 Answers   Student,


#if something == 0 int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }

1 Answers  


#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }

3 Answers  


main() { clrscr(); } clrscr();

2 Answers  






Categories