0

What are the difference between ++x and x++? And how to understand this x+=2?

24th Oct 2017, 1:46 PM
Ceejay
Ceejay - avatar
7 Answers
+ 13
++x increments the value of x and then returns x. On the other hand, x++ returns the value of x and then increments it. For example: int a=0; System.out.print(a++); the output will still be 0, as it uses the value of a and only then adds 1. But if we look at the following example: int b=0; System.out.print(++b); the output will be 1, as it adds 1 before using the value of b... but after both codes will be executed, the value of a and b will be 1. x += 2 has the meaning as that of x = x + 2 There are some similar posts, refer: https://www.sololearn.com/Discuss/160327/?ref=app https://www.sololearn.com/Discuss/160327/what-is-the-difference-between-x-x-x-and-x https://www.sololearn.com/Discuss/336732/what-is-the-difference-between-x-and-x https://www.sololearn.com/Discuss/305422/x-and-x https://www.sololearn.com/Discuss/56740/what-is-the-difference-between-x-and-x
24th Oct 2017, 1:50 PM
Dev
Dev - avatar
+ 4
@Christine, just a tips, the Q&A Discussion & Code Playground has a Search feature, you can use it to find something you have interest with, learn to use it, by that you'd be doing the community a favor, by reducing duplicate questions, do tell and share this with your friends :)
24th Oct 2017, 2:01 PM
Ipang
+ 1
Thank you Dev for your response in my question šŸ˜Š
24th Oct 2017, 1:56 PM
Ceejay
Ceejay - avatar
+ 1
hahaha nice battlešŸ˜
3rd Nov 2017, 5:47 PM
Ceejay
Ceejay - avatar
0
Completed 3 Challenges uhh.. Nice
3rd Nov 2017, 5:43 PM
Mahesh Kase
0
Where u from..
3rd Nov 2017, 5:50 PM
Mahesh Kase
0
Nice...
3rd Nov 2017, 6:03 PM
Mahesh Kase