What is really happening in this code?

后端 未结 6 465
轮回少年
轮回少年 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:06

    1. The function count is called with an integer argument of 10.
    2. Since the function argument m which is 10 is greater than 0 the function count calls itself with an integer argument of m which is 10 minus 1 which equals 9.
    3. Step 2 repeats with varying arguments (m-1) until m is not greater than 0 and which point the program prints the value of m.

    The recursive function just modifies the parameter given to it and calls itself with that modified value until the desired result is returned (in this case m not being greater than 0).

提交回复
热议问题