Pages

Wednesday, July 16, 2014

What is the technical difference between PREFIX & POSTFIX versions of INCREMENT & DECREMENT OPERATORS?


Let’s assume var A= 3; and var B=6; below you can see 4 different ways of incrementing and decrementing a variable value. At the end of each operation the end result is same. It doesn’t matter whether you are using A=A+1; or A+=1; or A++; or ++A; it will give A=4 as the end result of each.



But let us discuss what the difference is between A++; (POSTFIX) & ++A; (PREFIX) operators. To identify the difference clearly you can use the code given below.


This means when you use prefix it will increment or decrement the value through the execution and if you use postfix it will increment or decrement the value at the end of the execution process of the particular instruction (after the semicolon).

No comments:

Post a Comment