-2

Is there a difference between x++ and ++x in memory? is relative about programming language?

real
  • 11
  • 2
  • 1
    What do you mean by "in memory"? – Tunaki Nov 18 '15 at 15:35
  • 2
    Possible duplicate of [Is there a difference between x++ and ++x in java?](http://stackoverflow.com/questions/1094872/is-there-a-difference-between-x-and-x-in-java) – Jordi Castilla Nov 18 '15 at 15:38
  • Hmm. Java works with an operand stack. So there will be differences in the values in the operand stack - but is that what you mean at all? – RealSkeptic Nov 18 '15 at 15:39
  • I know the result. one is a preincrement,another is a postincrement. when I using the expression, what will memory do ? – real Nov 18 '15 at 15:48
  • It's different everywhere. Even within java because it depends on whether is actually uses the operand stack or simply optimizes the difference away. E.g. a `for(..; i++)` loop is identical to a `for(..; ++i)` loop and the compiler / runtime will make the most efficient version out of it that behaves according to your specification. – zapl Nov 18 '15 at 15:49

1 Answers1

1

The only way memory is affected is in the difference of moments when the value is modified. As you probably know, ++x makes the increment before the processing, whereas x++ makes the increment after the processing.

Nacho321
  • 1,911
  • 7
  • 33
  • 55
  • whether using x++ ,memory will copy the value of x to another memory area,then it make a increment. while using ++x, it make a increment directly. If so, ++x is more effective than x++? – real Nov 18 '15 at 15:42