+ 1

Please tell me the difference?(Related to incrementation)

++x and x++ What's the difference and where they are helpful. Please and Thanks

6th Apr 2017, 1:21 AM
Maulik Bharatsinh Parmar
Maulik Bharatsinh Parmar - avatar
3 Answers
+ 5
++x is Pre increment meaning, increment is done first. For example, y = ++x means x = x + 1 and y = x. If x is 1 initially, y becomes 2. x++ is Post increment meaning, increment is done last. For example, y = x++ means y = x and x = x + 1. If x is 1 initially, y becomes 1.
6th Apr 2017, 1:25 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 1
quick example pre increment means value is incremented prior to being used, post increment means value is incremented after it was used int i = 1; System.out.println (++i); // i is now 2. prints 2 vs int i = 1; System.out.println (i++); // prints 1, but i is now 2
6th Apr 2017, 2:33 AM
Edward
0
Thanks
6th Apr 2017, 1:29 AM
Maulik Bharatsinh Parmar
Maulik Bharatsinh Parmar - avatar