Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Noob Question
01-17-2012, 06:12 PM #1
- Join Date
- Jan 2012
- Thanked 0 Times in 0 Posts
int variableA = 10;
int variableB = 10;
System.out.println ( ++variableA )
System.out.println ( variableB++ )
Why does variableA = 11 and variableB = 10?
01-17-2012, 06:22 PM #2
The increment/decrement operators can be applied before (prefix) or after (postfix) the operand. The code result++; and ++result; will both end in result being incremented by one. The only difference is that the prefix version (++result) evaluates to the incremented value, whereas the postfix version (result++) evaluates to the original value. If you are just performing a simple increment/decrement, it doesn't really matter which version you choose. But if you use this operator in part of a larger expression, the one that you choose may make a significant difference.