最后的結果為什么是100??不應該是101??
#include <stdio.h>
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;
}
#include <stdio.h>
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;
}
2016-09-10
舉報
2016-09-10
int x=100; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 輸出的數 ? ? ? x的值
??? printf("%d\n",x++); ? 1 ? ? ? ? ? ? ? ? 101 ? ? ? ? ? ? 101
??? printf("%d\n",++x); ? 2 ? ? ? ? ? ? ? ? 102 ? ? ? ? ? ? 102
??? printf("%d\n",--x); ? ? 3 ? ? ? ? ? ? ? ? 101 ? ? ? ? ? ? 101
??? printf("%d\n",x--); ? ? 4 ? ? ? ? ? ? ? ? 101 ? ? ? ? ? ? 100
??? printf("%d\n",x+1); ? 5 ? ? ? ? ? ? ? ? ?101 ? ? ? ? ? ? 100
??? printf("%d\n",x); ? ? ? 6 ? ? ? ? ? ? ? ? ?100 ? ? ? ? ? ?100
1-4行輸出完后,x的值都變了,而第5行輸出完,x的值沒有變,還是100,所以最后輸出的x的值是100
2016-09-10
#include <stdio.h>
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);//問題出在這兒,你這只是輸出一個x+1的數,而不是對x進行更改,,若你想輸出100,102,101,101,100,101,那么正確的應該是x++,若是后面都是101,那就是++x,按照計算機的思維,而不是我們規定的人的思維思考//
??? printf("%d\n",x);
??? return 0;
}
2016-09-10
因為之前四個輸出相當于是x=x+1和x=x-1;改變了x的值
第五個輸出并沒有把x+1的結果賦值給x,輸出結果是101但是沒有改變x的值
所以最后一個輸出依舊是100