0
What are the difference between ++x and x++? And how to understand this x+=2?
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
+ 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 :)
+ 1
Thank you Dev for your response in my question š
+ 1
hahaha nice battleš
0
Completed 3 Challenges uhh.. Nice
0
Where u from..
0
Nice...