解释评价;顺序printf中 [英] Explain the order of evalution in printf
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/376278/parameter-evaluation-order-before-a-function-calling-in-c\">Parameter调用用C 一个函数前评估顺序
块引用>的main()
{
INT I = 5;
的printf(%D%D%D,我+ +,我 - ,+ +我 - 我,我);
}输出为45545,但我不它是如何工作的。有人说,在函数调用的参数被压入堆栈中从左至右。
解决方案的顺序,其中的参数被传递未在标准中定义,并且由调用约定的编译器使用。
我觉得你的情况, CDECL 调用约定(其中许多C编译器使用x86架构)使用其中一个函数的参数获得由右至左求值。Possible Duplicate:
Parameter evaluation order before a function calling in C
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }
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.
解决方案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屋!