精華區beta C_and_CPP 關於我們 聯絡資訊
※ 引述《fishforpt (游來游去的)》之銘言: : #include<stdio.h> : #include<stdlib.h> : int main() : { : int z=-1; : printf("%d ", ++z); : printf("%d ", z--); : printf("%d ", z++ + z); : printf("%d ", z + z++); : system("pause"); : return 0; : } : : c卻跑出來 0 0 -2 0 : : 為什麼阿~~~~為什麼~~~~~ : 各位板大救命阿~~~~ : : -- : ※ 發信站: 批踢踢實業坊(ptt.cc) : ◆ From: 59.104.160.134 : ※ fishforpt:轉錄至看板 java 02/02 00:36 : 推 cjcat2266:是不是因為兩種語言的operator precedence不一樣? 02/02 00:47 : 推 y2k27:是哪間公司這麼優秀考這個? 02/02 03:13 : → y2k27:我猜有side effects發生 結果視平台實作而定 沒有標準答案 02/02 03:13 [ISO C99, 6.5.2.4 Postfix increment and decrement operators] The side effect of updating the stored value of the operand shall occur between the previous and the next sequence point. 標準說這動作在兩個 expression 之間完成。 我也很想知道是哪間公司出這種題目。 -- Licensed under CC2.5(TW) by-sa, Samael Wang. http://creativecommons.org/licenses/by-sa/2.5/tw/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.82.153 ※ 編輯: freesamael 來自: 220.135.82.153 (02/02 03:27)
oohay:沒錯啊,題目的確表達出C有那種狀況不是嗎? 02/02 04:28