search

Home  >  Q&A  >  body text

Solve the problem of ++

var x=10;

var y=20;

y = x;//y=31

y=x y;//y=30

Why are the values ​​different? Isn’t y=x y 31?

MrSwanMrSwan2416 days ago1561

reply all(3)I'll reply

  • 灭绝师太

    灭绝师太2018-04-12 13:02:48

    Because when the code is parsed, it is not parsed into

    x+ ++y

    but into

    x++ +y


    reply
    2
  • MrSwan

    Oh oh oh, okay, thank you teacher

    MrSwan · 2018-04-12 13:06:27
    灭绝师太

    ++x increases by 1 before use; x++ increases by 1 after use.

    灭绝师太 · 2018-04-12 13:09:51
  • Cancelreply