User manual

Table Of Contents
238
mikoC PRO for PIC32
MikroElektronika
Binary Arithmetic Operators
Division of two integers returns an integer, while remainder is simply truncated:
/* for example: */
7 / 4; /* equals 1 */
7 * 3 / 4; /* equals 5 */
/* but: */
7. * 3. / 4.; /* equals 5.25 because we are working with oats */
Remainder operand % works only with integers; the sign of result is equal to the sign of the rst operand:
/* for example: */
9 % 3; /* equals 0 */
7 % 3; /* equals 1 */
-7 % 3; /* equals -1 */
Arithmetic operators can be used for manipulating characters:
‘A’ + 32; /* equals ‘a’ (ASCII only) */
‘G’ - ‘A’ + ‘a’; /* equals ‘g’ (both ASCII and EBCDIC) */
Unary Arithmetic Operators
Unary operators ++ and -- are the only operators in C which can be either prex (e.g. ++k, --k) or postx (e.g. k++,
k--).
When used as prex, operators ++ and -- (preincrement and predecrement) add or subtract one from the value of the
operand before the evaluation. When used as sufx, operators ++ and -- (postincrement and postdecrement) add or
subtract one from the value of the operand after the evaluation.
For example:
int j = 5;
j = ++k; /* k = k + 1, j = k, which gives us j = 6, k = 6 */
but:
int j = 5;
j = k++; /* j = k, k = k + 1, which gives us j = 5, k = 6 */