有什么两个位置之间的区别? [英] What is the difference between the two locations?

查看:179
本文介绍了有什么两个位置之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个递归程序。当的printf 在函数中使用,其输出123和外部使用时,它输出0123。

I have a recursive program. When the printf is used in the function, it outputs 123 and when used outside, it outputs 0123 .

#include <stdio.h>

fact(int);
int main()
{
    int x=3;
    fact(x);
    printf("\n");
    system("PAUSE");
}

int fact(int y)
{
    if (y > 0)
    {
         fact(y-1);
         printf("%d",y);  
    }
    //printf("%d",y);   
}   

我并不是在同一时间同时使用的printf 。有什么区别呢这个位置的printf 语句创建?

I am not using both the printf at the same time . What difference does the location of this printf statement create?

推荐答案

其实(INT)是由下列顺序调用,

fact(int) is called by following sequence,

其实(3) - >事实(2)--->事实(1)--->事实(0)

fact(3)-->fact(2)--->fact(1)--->fact(0)

最后一个电话是事实(0)。根据对事实的实现(INT),当0被传递,如果printf()函数是用来outsite 0被打印出来。 0,如果printf()函数的内部使用不打印。

The last call is fact(0). According to the implementation of fact(int), when 0 is passed in, 0 is printed if printf() is used outsite. 0 is not printed if printf() is used inside.

其实,传入事实(INT)所有的值时的printf()是outsite用于打印。

In fact, all the values passed into fact(int) is printed when printf() is used outsite.

这篇关于有什么两个位置之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆