解释printf中的评估顺序 [英] Explain the order of evaluation in printf

查看:60
本文介绍了解释printf中的评估顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

main()
{
    int i=5;
    printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}

输出为45545,但我不知道它是如何工作的.有人说函数调用中的参数从左到右被压入堆栈.

Output is 45545, but I don't how it is working. Some say that the arguments in a function call are pushed into the stack from left to right.

推荐答案

标准中未定义传递函数参数的顺序,该顺序由 cdecl 调用约定(很多C编译器用于x86体系结构)用于从右到左评估函数中的参数.

The order in which the parameters to a function are passed is not defined in the standard, and is determined by the calling convention used by the compiler. I think in your case, cdecl calling convention (which many C compilers use for x86 architecture) is used in which arguments in a function get evaluated from right to left.

这篇关于解释printf中的评估顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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