|
|
Arithmetic Operators |
|
+, -, *, /, ++, -- and % are the arithmetic
operators.
+, -, *, / have expected behavior and apply to both
floating point and integer numbers.
% is the modulus operator. Returns the integer
remainder of dividing two integers. Cannot be applied to floating
point numbers.
++ adds one to the operand
-- subtracts one from the operand
Both ++ and -- can be used before or after the variable name. If it is before the variable name, then the value is incremented before the variable is used. If it is after the variable name, then the value is decremented before the variable is used.
Example
long i = 5; long j;
j = i++; /* j has value 5, i is now 6 */
j = ++i; /* i and j both now have value 7 */