Confused about the function return value

前端 未结 6 1874
予麋鹿
予麋鹿 2021-01-15 11:12
#include
using namespace std;
int Fun(int x)
{
    int sum=1;
    if(x>1)
        sum=x*Fun(x-1);
    else
        return sum;
}
int main()
{
             


        
6条回答
  •  爱一瞬间的悲伤
    2021-01-15 12:16

    Usually, EAX register is used to store return value, ad it is also used to do other stuff as well.

    So whatever has been loaded to that register just before the function returns will be the return value, even if you don't intend to do so.

    You can use the -S option to generate assembly code and see what happened to EAX right before the "ret" instruction.

提交回复
热议问题