+ 4

Can someone explain what the difference in usage would be between ++x and x++?

Difference between ++x and x++

10th Mar 2017, 2:23 PM
Freia Van Loon
Freia Van Loon - avatar
2 Answers
+ 11
++x is prefix increment operator...it means that first it will increase its value by 1 & then it will assign the value to the variable. eg x=5 b=++x so first the x will become 6 then it will assign this value to b, thus b= 6 & x= 6 x++ is postfix increment operator... it means that first it will assign the value to variable and then it will increase its value by 1. eg. x=5 b=x++ so now..first x will give the value 5 to b then it will increase its value by 1. Thus b= 5 & x=6
10th Mar 2017, 2:46 PM
Dolu
Dolu - avatar
0
If the operator appears before the variable, it increments the variable before returning its value. If the operator appears after the variable, it increments the variable after returning its value.
3rd Jun 2017, 12:47 AM
Theaddictivelearning sandeep
Theaddictivelearning sandeep - avatar