edited by
640 views
1 votes
1 votes
void foo(int x) {
    if(x > 0) {
        foo(--x);
        printf("%d",x++);
        foo(--x);
    }
}

What will the output when the above function is called as foo(3) ?

Please provide recursion tree or stack diagram whichever you use to answer.

Edit :: How would the answer change if it was

void foo(int x) { 
    if(x > 0) { 
        foo(--x); 
        printf("%d",x); 
        foo(--x); 
        }
      }
edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
1
Anirudh Kaushal asked Apr 6, 2022
191 views
#include<stdio.h struct marks { int p:3; int c:3; int m:2; }; void main() { struct marks s = {2, -6, 5}; printf("%d %d %d", s.p, s.c, s.m); }What does p:3 means here ?
0 votes
0 votes
0 answers
2
bts1jimin asked Jan 20, 2019
311 views
0 votes
0 votes
1 answer
3
Parshu gate asked Nov 19, 2017
359 views
#include<stdio.h>int main(){ int a=2;if(a==2){ a=~a+2<<1; printf("%d",a);}}
4 votes
4 votes
1 answer
4
A_i_$_h asked Nov 11, 2017
638 views
void foo(int *); main() { int x=30 , *a=&x; foo(a++); } void foo(int *a) { printf("%d", *a); }