|
|
Re: Post increment problem
|
Posted: May 9, 2005 4:59 AM
|
|
Java offers 2 versions of this operator.
The postfix form changes the value after the assignment is executed, the prefix operator does it before the assignemnt is executed.
Example:public static void main(String[] args) {
int m = 7;
int n = 7;
int a = 2 * ++m; //a is 16, m = 8
int b = 2 * m++; //b is 14, m = 8, the increment operator was executed after the "=" operation.
}
It is recommended not to use the ++ operator inside a line with multiple operations.
A common joke about C++: The language should be called ++C, because we want to use it AFTER it was improved.
|
|