需要一些解释 [英] Need some explanation

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

问题描述

你好,

1)首先如何执行以下程序我的意思是如何打印输出

以及为什么后续程序在Turbo中提供不同的输出

C ++编译器和Visual c ++ 6编译器?

void main()

{

int val = 5;

printf("%d%d%d%d",val, - val,++ val,val--);

}

under turbo编译器给它

4 4 5

并且在visual c ++下它的

5 5 6 5


2)如何评估以下声明

int val = 5;

val = - --val - val-- - --val;

hello,
1) First how following program get executed i mean how output is
printed and also why following program gives different output in Turbo
C++ compiler and Visual c++ 6 compiler?
void main()
{
int val=5;
printf("%d %d %d %d",val,--val,++val,val--);
}
under turbo compiler its giving
4 4 5 5
and under visual c++ its
5 5 6 5

2) How to evaluate following statement
int val =5;
val =- --val - val-- - --val;

推荐答案



ra*******@gmail.com 写道:
你好,
1)首先如何执行以下程序我的意思是如何打印输出以及为什么以下程序在Turbo
C ++编译器和Visual c ++ 6编译器中提供不同的输出?
#include< stdio.h> void main()
不是main的可移植标准定义,使用:

int main(/ * int argc,char ** argv * /){
int val = 5;
printf("%d%d%d%d",val, - val,++ val,val--);
/ *从主要下跌,是一个相当新近的C99以后,AFAIK,

因此* /

返回0;在turbo编译器下给它
4 4 5 5
并在visual c ++下它的
5 5 6 5
评估printf的参数的顺序是*不是*

在不同的编译器/系统对中相同。 2)如何评估以下陈述
int val = 5;
val = - --val - val-- - --val;
hello,
1) First how following program get executed i mean how output is
printed and also why following program gives different output in Turbo
C++ compiler and Visual c++ 6 compiler? #include <stdio.h> void main() is not a portable standard definition for main, use:
int main(/*int argc, char **argv*/) {
int val=5;
printf("%d %d %d %d",val,--val,++val,val--); /*falling off main, is a rather recent addition C99 onwards, AFAIK,
hence*/
return 0; }
under turbo compiler its giving
4 4 5 5
and under visual c++ its
5 5 6 5 The order in which the arguments to printf are evaluated is *not* the
same across different compiler/system pairs. 2) How to evaluate following statement
int val =5;
val =- --val - val-- - --val;



你可能会喜欢阅读常见问题解答,以及副作用和

序列点的一些内容。


You might like to read the FAQ, and some stuff on side-effects and
sequence points.



ra*******@gmail.com 写道:
你好,
1)首先如何执行以下程序我的意思是如何打印输出以及为什么后续程序在Turbo
C ++编译器和Visual c ++ 6编译器中提供不同的输出?
void main ()
{val = 5;
printf("%d%d%d%d",val, - val,++ val,val - ); <在turbo编译器下它给出了4 4 5 5
并在visual c ++下它的
5 5 6 5

2)如何评估以下声明
int val = 5;
val = - --val - val-- - --val;
hello,
1) First how following program get executed i mean how output is
printed and also why following program gives different output in Turbo
C++ compiler and Visual c++ 6 compiler?
void main()
{
int val=5;
printf("%d %d %d %d",val,--val,++val,val--);
}
under turbo compiler its giving
4 4 5 5
and under visual c++ its
5 5 6 5

2) How to evaluate following statement
int val =5;
val =- --val - val-- - --val;




转到 http://www.eskimo.com/~scs/C-faq/s3.html



Goto http://www.eskimo.com/~scs/C-faq/s3.html.


ra ******* @ gmail.com 写道:
你好,
1)首先如何执行以下程序我的意思是如何打印输出以及为什么后续程序在Turbo中提供不同的输出
C ++编译器和Visual c ++ 6编译器?
void main()
{val = 5;
printf("%d%d%d%d",val, --val,++ val,val--);
}
在turbo编译器下给它
4 4 5 5
并在visual c ++下它的
5 5 6 5

2)如何评估以下陈述
int val = 5;
val = - --val - val-- - --val;
hello,
1) First how following program get executed i mean how output is
printed and also why following program gives different output in Turbo
C++ compiler and Visual c++ 6 compiler?
void main()
{
int val=5;
printf("%d %d %d %d",val,--val,++val,val--);
}
under turbo compiler its giving
4 4 5 5
and under visual c++ its
5 5 6 5

2) How to evaluate following statement
int val =5;
val =- --val - val-- - --val;




在第一种情况下,行为是未定义的(

函数参数的评估顺序)。 (2)中的陈述非常难以阅读,并且

应该(在实践中)被重写为更易于理解的东西。


此外:


- `void main()''不是主函数的有效ANSI C签名。


- 你还没有包含stdio.h


- 您的编码风格不一致,缩进很奇怪

至少可以说。



In the first case the behavior is undefined (evaluation order of
function parameters). The statement in (2) is very hard to read and
should (in practice) be rewritten into something more comprehensible.

Moreover:

- `void main()'' is not a valid ANSI C signature for the main function.

- You have not included stdio.h

- Your coding style is inconsistent and the indentation is strange to
say the least.


这篇关于需要一些解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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