What is really happening in this code?

后端 未结 6 460
轮回少年
轮回少年 2020-12-03 16:51

I have a code which includes a recursive function. I have wasted a lot of time on recursion but I still couldn\'t get it really:

#include
void         


        
6条回答
  •  渐次进展
    2020-12-03 17:15

    Each number refers to the line number.

    #include
    count(int);
    main()
    {
    1int x=10,z;
    2count(x);
    }  
    count(int m)
    {
    3if(m>0)
    4   count(m-1);
    5printf("%d",m);
    }
    

    The execution happens like this(with x=3) -

    line number|value of x

    1 3

    2 3

    3 3

    4 2

    3 2

    4 1

    3 1

    4 0

    5 0

    5 1

    5 2

    5 3

    Numbers printed on the screen 0 1 2 3

提交回复
热议问题