+ 2
[DUPLICATE] Difference between ++a and a++. Explain with example .
3 Answers
+ 5
++a is called prefix operator
a++ is called postfix operator
++a ( compiler assigns +1 before reading value of the variable )
a++ ( compiler reads the value of the variable first then adds 1 )
+ 2
int a = 0; // a is 0
int b = ++a; // a becomes 1, b is 1
int c = a++; // c is 1, a becomes 2
// a=2, b=1, c=1
a++; // a becomes 3
++a; // a becomes 4
// no real difference between the last two statements.
https://www.sololearn.com/Discuss/966359
https://www.sololearn.com/Discuss/666244
https://www.sololearn.com/Discuss/533640