Mathematical Operators




The Mathematical Operators allow you to do arithmetic.

The order of operations is the same as in Algebra.


-       unary negative sign

* / %   multiply  divide  modulus
+ -     add or substract


Note:  When you do a math operation on two unlike types,
the smaller type is promoted to the higher type.
For example, if you add a double and an int, the int is 
converted to a double inside the cpu.

Alert: When you divide two ints (or any int types), the result
is stored as an int (i.e. you will lose any decimal part).


Examples:

int a,b,c; b = 13; c = 5; a = b + c; // a would receive the value 18 a = b / c; // a would receive the value 2 (decimal part truncated) a = b % c; // a would receive the value 3 (the remainder)