Re: [問題] 2題程式不懂,是要怎麼看呢?
※ 引述《irene6524 (Irene)》之銘言:
: int a=11,b=11;
: a+=a+=b+=b%=b<<2;
a+=a+=b+=b%=b<<2;
把簡式還原為正式語法
=> [a] = a + (a+=b+=b%=b<<2)
=> [a] = a + (a = a + (b+=b%=b<<2) )
=> [a] = a + (a = a + (b = b + (b%=b<<2) ) )
=> [a] = a + (a = a + (b = b + (b = b % (b<<2)) ) )
把 定義 代入 a=11, b=11
==>[a] = a + (a = a + (b = b + (b = b % (11 << 2 )))) [ b << 2 =44]
==>[a] = a + (a = a + (b = b + (b = 11 % 44)))) [ b=11 % 44 = 11 ] 這時b=11
==>[a] = a + (a = a + (b = 11 + 11)) [ b = 11 + 11 = 22] 這時b=22,代入a=11
==>[a] = a + (a = 11 + 22) [a = 11 + 22 = 33] 這時 a = 33
==>[a] = 33 + 33 [a = 33 + 33 = 66] 這時 a = 66
所以輸出 a = 66
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.75.244.133
※ 文章網址: http://www.ptt.cc/bbs/CSSE/M.1412238479.A.CBC.html
→
10/02 16:46, , 1F
10/02 16:46, 1F
→
10/02 16:49, , 2F
10/02 16:49, 2F
→
10/02 16:50, , 3F
10/02 16:50, 3F
討論串 (同標題文章)
CSSE 近期熱門文章
PTT數位生活區 即時熱門文章