prev

Arithmetic Operators

next
  1. +, -, *, /, ++, -- and % are the arithmetic operators.

  2. +, -, *, / have expected behavior and apply to both floating point and integer numbers.

  3. % is the modulus operator. Returns the integer remainder of dividing two integers. Cannot be applied to floating point numbers.

  4. ++ adds one to the operand

  5. -- subtracts one from the operand

  6. 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.

  7. 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 */