What is the difference? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

What is the difference?

What is the difference between a++ and ++a?

9th Nov 2016, 2:41 PM
Mystery
Mystery - avatar
3 Réponses
+ 5
a++ is post increment and ++a is pre increment. Say,a=5 y=++a Answer: y=6 a=6 Whereas, y=a++ Answer: y=5 a=6
9th Nov 2016, 2:45 PM
Mystery
Mystery - avatar
+ 2
For instance we have a integrer (variable) named a and is equal to 5. So, if we write y=++x, both y and x gets equal to 6, but if we write y=x++, y takes the value 5 and x = 6. In the first case, x is increased by 1 before is assigned to y, while this doesn't happen in the second one (y=x and then x=x+1). Understood?
9th Nov 2016, 8:28 PM
Georgios Bariamai
Georgios Bariamai - avatar
+ 1
Yep👍 Thanks! !
10th Nov 2016, 4:11 AM
Mystery
Mystery - avatar