#包括< studio.h> main(){int x = 10,y;打印(“输入一个数字”);扫描(“%d”,& x); y = x ++ + ++ x + ++ x + ++ x + ++ x; print(" result:%d",y):; [英] #include<studio.h> main() { int x=10, y; print("enter a number"); scan ("%d", &x); y=x++ + ++x + ++x + ++x + ++x; print("result:%d", y):;
问题描述
对于手动计算得到64但在turbo C编译器得到70和在Java 64中它如何变化可以有人解释
我尝试过:
如果通过手动计算得到答案64取x = 10但是在编译器得到70怎么可能
简单:为什么x = ++ x + x ++给我错误的答案吗? [ ^ ]
顺便说一句:以后,请不要把你的代码作为主题 - 这就是我尝试过的东西。主题应该简短而甜蜜,并尽可能快速地用英语概述问题。也许x ++给出了错误答案或类似内容?
你处于灰色区域:代码合法,但不可预测。
y = x ++ + ++ x + ++ x + ++ x + ++ x;
编译器可以自由重新排序此代码中的内容。对于x = 10,
,y可以是50到75之间的任何值。
唯一的建议是:永远不要在一行代码中混淆多个递增/递减操作。
For manual calculation getting 64 but in turbo C complier getting 70 and in Java 64 how it varies can anyone explain
What I have tried:
If taking x=10 by doing the manual calculation getting the answer 64 but in complier getting 70 how is it possible
Simple: Why does x = ++x + x++ give me the wrong answer?[^]
BTW: in future, don't put your code as the subject line - that's what "What I have tried" is there for. The subject line should be short and sweet, and quick overview of the problem in English as much as possible. Perhaps "x++ giving wrong answer" or similar?
You are in gray zone: the code is legal, but unpredictable.
y=x++ + ++x + ++x + ++x + ++x;
The compiler is free to reorder what is in this code.
for x=10, y can be anywhere between 50 and 75.
The only advice is: never mess with multiple increment/decrement operations in a single line of code.
这篇关于#包括< studio.h> main(){int x = 10,y;打印(“输入一个数字”);扫描(“%d”,& x); y = x ++ + ++ x + ++ x + ++ x + ++ x; print(" result:%d",y):;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!