0

What's the difference between a++ and ++a or a-- and --a ?? Thanks.

a++ and ++a

23rd Dec 2016, 9:56 PM
Made With Love
Made With Love - avatar
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.
23rd Dec 2016, 10:07 PM
Tamra
Tamra - avatar
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.
23rd Dec 2016, 10:07 PM
VPA
VPA - avatar
0
got it :D that's easy!
23rd Dec 2016, 10:11 PM
Made With Love
Made With Love - avatar