C程序给出了一个输出上不同的编译器不同 [英] C program gives an output different on different compiler

查看:134
本文介绍了C程序给出了一个输出上不同的编译器不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑了一个C程序,并得到了不同的C编译器不同的输出。以下是
我的程序

I ran a C program and got different output on different C compilers. Below is my program

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

在boarnland C ++编译器O / P是

ON boarnland c++ complier o/p is

45545

和海合会及其

45555

是不是真的编译或依赖其操作系统依赖?

is it really compiler dependent or its OS dependent?

在函数调用的参数被压入堆栈中从左至右。评价是通过从堆栈中弹出的。和评价是由右至左,故结果

The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.

推荐答案

您不能依赖的副作用,执行顺序为参数的函数上。在这种情况下,2编译器执行的副作用以不同的顺序,产生不同的结果。

You cannot rely on the order of execution of side effects to arguments to a function. In this case the 2 compilers are executing the side effects in a different order, producing different results.

这篇关于C程序给出了一个输出上不同的编译器不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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