[問題] i=5; j=++i + ++i + ++i; j=22...
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
linux
codeblock
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
剛剛在網路上亂看,看到標題中的這個問題
我實在是想不透為甚麼= =
餵入的資料(Input):
預期的正確結果(Expected Output):
j = 21
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
int i = 5;
int j= ++i + ++i + ++i; cout << j <<endl;
//以下是我加入測試的
i = 5;
cout << ++i << endl;
cout << ++i << endl;
cout << ++i << endl;
i = 5;
j = 0;
j = ++i + ++i; cout << j << endl; // 這邊j是14,代表第二次++i讓i變成8 ?
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 24.5.242.122
※ 編輯: andrenvq57 來自: 24.5.242.122 (01/10 16:54)
→
01/10 16:55, , 1F
01/10 16:55, 1F
噓
01/10 16:56, , 2F
01/10 16:56, 2F
→
01/10 16:58, , 3F
01/10 16:58, 3F
→
01/10 17:01, , 4F
01/10 17:01, 4F
→
01/10 17:02, , 5F
01/10 17:02, 5F
→
01/10 17:03, , 6F
01/10 17:03, 6F
→
01/10 17:04, , 7F
01/10 17:04, 7F
謝了各位 我又上了一課
※ 編輯: andrenvq57 來自: 24.5.242.122 (01/10 17:10)
→
01/10 18:05, , 8F
01/10 18:05, 8F
→
01/10 18:05, , 9F
01/10 18:05, 9F
噓
01/10 18:05, , 10F
01/10 18:05, 10F
→
01/10 18:43, , 11F
01/10 18:43, 11F
推
01/10 19:03, , 12F
01/10 19:03, 12F
推
01/10 19:37, , 13F
01/10 19:37, 13F
→
01/11 08:32, , 14F
01/11 08:32, 14F
噓
01/11 23:34, , 15F
01/11 23:34, 15F
噓
01/12 12:56, , 16F
01/12 12:56, 16F
推
01/12 20:03, , 17F
01/12 20:03, 17F
推
01/13 05:16, , 18F
01/13 05:16, 18F