输出取决于编译器 [英] does the output depends on the compiler
本文介绍了输出取决于编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
这个命令的输出取决于编译器。
int val = 1234;
int * ptr =& val;
printf("%d%d%d",val,* ptr ++,++ * ptr);
O / p
i期待1234,1234,1235。
但我得到了1235,1235,1235 >
推荐答案
sunny写道:
sunny wrote:
嗨所有
这个命令的输出取决于编译器。
int val = 1234;
int * ptr =& val;
printf("%d%d%d",val,* ptr ++,++ * ptr);
O / p
i期待1234,1234,1235。
但我得到了1235,1235,1235
Hi All
does the output of this command depend on the compiler.
int val=1234;
int* ptr=&val;
printf("%d %d %d",val,*ptr++,++*ptr);
O/p
i was expecting 1234,1234,1235.
but i got 1235, 1235, 1235
>
sunny写道:
sunny wrote:
嗨所有
输出这个命令取决于编译器。
int v al = 1234;
int * ptr =& val;
printf("%d%d%d",val,* ptr ++,++ * ptr) ;
O / p
i期待1234,1234,1235。
但我得到了1235,1235,1235
Hi All
does the output of this command depend on the compiler.
int val=1234;
int* ptr=&val;
printf("%d %d %d",val,*ptr++,++*ptr);
O/p
i was expecting 1234,1234,1235.
but i got 1235, 1235, 1235
sunny写道:
sunny wrote:
大家好
此命令的输出是否依赖于编译器。
Hi All
does the output of this command depend on the compiler.
int val = 1234;
int * ptr =& val;
printf (%d%d%d,val,* ptr ++,++ * ptr);
O / p
i期待1234,1234 ,1235。
但我得到1235,1235,1235
int val=1234;
int* ptr=&val;
printf("%d %d %d",val,*ptr++,++*ptr);
O/p
i was expecting 1234,1234,1235.
but i got 1235, 1235, 1235
您的代码有未定义的行为。你正在改变ptr,并且
阅读它不止一次在一个序列点之间,如果你想让程序正常运行,你就不应该这样做。
它也是未定义的功能的顺序参数是
评估。
Your code has undefined behaviour. You''re altering ptr, and
"reading" it more than once between a sequence point, which
you should not do if you want the program to behave properly.
It''s also undefined in which order arguments to functions are
evaluated.
这篇关于输出取决于编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文