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

前端 未结 4 1237
面向向阳花
面向向阳花 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:29

    We always work left to right the Parens just group parts of the sum.So just remember always go left to right. I have gone step by step below

    start with the question

    a = 5

    b = a + (a = a + 5)

    So now change the first 'a' to a 5

    b = 5 + (a = a + 5)

    now lets do the sum in the parens

    b = 5 + (a = 5 + 5)

    This gives us

    b = 5 + 10 or you could say b = 5 + (a = 10)

    and the answer is

    b = 15

    also now

    a = 10

提交回复
热议问题