一模一樣的程序答案不一樣?求大神指點
#include
int main() { ? ?int x = 100; ? ?printf("%d\n",++x); ? ?printf("%d\n",x++); ? ?printf("%d\n",--x); ? ?printf("%d\n",x--); ? ?printf("%d\n",x+1); ? ?printf("%d\n",x); ? ?return 0; } 101 101 101 101 101 100 為啥結果與答案不符呀!#include
int main() { ? ?int x = 100; ? ?printf("%d\n",++x); ? ?printf("%d\n",x++); ? ?printf("%d\n",--x); ? ?printf("%d\n",x--); ? ?printf("%d\n",x+1); ? ?printf("%d\n",x); ? ?return 0; } 101 101 101 101 101 100 為啥結果與答案不符呀!2017-10-05
舉報
2017-10-05
2017-10-05
printf("%d\n",++x); ? ?printf("%d\n",x++);2個位置調換了,原題目哪里是printf("%d\n",x++);他在前面輸出的結果為100,這個在printf("%d\n",++x);后面輸出101 a++先取值再換算所以結果是100 ++a是先取值再運算。你在仔細看看
2017-10-05
原來答案是什么呀,你也不說明白,原題,原答案,你讓我們怎么驗證,你現在的程序和答案是一致的
2017-10-05
你是看示例嗎?你的++x和x++的位置反掉了,所以結果是與示例不一樣的