WHAT IS PRE INCRENEMT?
The
pre-increment operator alters the value of the variable before using it in any
expression. Therefore, we can say that the pre-increment operator increases the
value of the variable first and then use it in the expression.
For an example: initial value of x = 5 find the value of y = ++x ?
Here first increment happens so know x = x + 1 = 5 + 1 = 6 (x = 6).
Then the value of x is assigned to y(y = 6).
Here x = 6 and y = 6
WHAT IS POST INCREMENT?
The
post-increment operator is used when it is required to increment the value of
the variable after evaluating the expression. Therefore, in post-increment
value is first used in the expression, and then it is incremented.
For an example: initial value of x = 5. find the value of y = x++ ?
Here first the initial value of x is assigned to y(y = 5).
After that the increment happens. So know x = x + 1 = 5 + 1 = 6 (x = 6).
finally y = 5 and x = 6.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLTCcBQTGwH-6PwKNhuv_SP66gBYvbOtYUXApKB2lRglROEmixiJEQ5i0jS2l04Kz2ODuqTn0CfFt0CH7xmyuQZG-MJLM66mv7DdlqT3C9Hdh-kJl3MAaD-U2odZzeCBt9cBGfcXWsU5f_aNb0adwhJ7E__a7cgxfR0daGfQD5Dg-eoh1HZ84nkY01Zuau/w640-h279/Difference+between+pre_post+increment+&+decrement+operators+in+Java_.jpg)
0 Comments
Post a Comment