What's happening with this expression? b = a + (a = a + 5)

前端 未结 4 1115
面向向阳花
面向向阳花 2021-01-30 15:47
a = 5
b = a + (a = a + 5)

result b = 15

Why the first \'a\' do not changes after that (a = a + 5)? But why second one changes? What exactly is

4条回答
  •  余生分开走
    2021-01-30 16:17

    The expression is always evaluated from left to right & then assigned to whatever on left hand. As

      a = 5
      b = a + (a = a + 5)
    \\b = 5 + (a = 5 + 5)
      b = 15
    

提交回复
热议问题