亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

array[j + 1] = array[j--]; 這個語句有問題么?

array[j + 1] = array[j--]; 這個語句有問題么?

C++
慕工程0101907 2019-03-15 17:45:13
int j; ... ...array[j + 1] = array[j--];array[j + 1] = array[j--]是否一定等價于array[j + 1] = array[j]; j--;?
查看完整描述

2 回答

?
慕娘9325324

TA貢獻1783條經驗 獲得超5個贊

C++17之前是UB。C++17確定了順序:賦值操作符的右側操作數先序于左側。所以左側得到的是自減后的值。故而array[j + 1] = array[j--];一般等價于(并發例外)

array[j] = array[j];
--j;
8.18.1[expr.ass] ...In all cases, the assignment is sequenced after the value computation of the right and left operands, and before the value computation of the assignment expression. The right operand is sequenced before the left operand...


查看完整回答
反對 回復 2019-03-15
?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

array[j + 1] = array[j--]; 屬于未定義行為。
兩個順序點之間訪問和修改了同一個對象。

查看完整回答
反對 回復 2019-03-15
  • 2 回答
  • 0 關注
  • 1210 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號