最后的結(jié)果為什么是100??不應(yīng)該是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
舉報(bào)
2016-09-10
int x=100; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 輸出的數(shù) ? ? ? 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);//問題出在這兒,你這只是輸出一個(gè)x+1的數(shù),而不是對x進(jìn)行更改,,若你想輸出100,102,101,101,100,101,那么正確的應(yīng)該是x++,若是后面都是101,那就是++x,按照計(jì)算機(jī)的思維,而不是我們規(guī)定的人的思維思考//
??? printf("%d\n",x);
??? return 0;
}
2016-09-10
因?yàn)橹八膫€(gè)輸出相當(dāng)于是x=x+1和x=x-1;改變了x的值
第五個(gè)輸出并沒有把x+1的結(jié)果賦值給x,輸出結(jié)果是101但是沒有改變x的值
所以最后一個(gè)輸出依舊是100