0
What's the difference between a++ and ++a or a-- and --a ?? Thanks.
a++ and ++a
3 Réponses
+ 5
++a and --a are preincrements/predecrements. They have very high precedence/priority. They'll increment/decrement 1 before most other operations (math, assigning, etc.)
a++ and a-- are postincrements/postdecrements. They have very low precedence. After all other operations are done (including assigning!), they'll increment/decrement 1.
Ex:
b = ++a //Adds 1 to a, then assigns a to b.
b = a++ //Assigns a to b, then adds 1 to a.
0
Post variants return the original value in addition to changing the actual variable. This might come with a cost, for example, when a copy has to made from an object when returning the original value.
0
got it :D that's easy!