|
|
HP C/HP-UX Reference Manual: Version A.05.55.02 > Chapter 5 Expressions
and Operators Arithmetic Operators (+, -, *, /, %) |
|
The addition, subtraction, and multiplication (+, -, and *) operators perform the usual arithmetic operations in C programs. The operands may be any integral or floating-point value, with the following exception:
The addition and subtraction operators also accept pointer types as operands. Pointer arithmetic is described in “Pointer Operators (*, ->, &)”. C's modulo operator (%) produces the remainder of integer division, which equals 0 if the right operand divides the left operand exactly. This operator can be useful for tasks such as determining whether or not a year is a U.S. presidential election year. For example: if (year % 4 == 0) As required by the ANSI/ISO C standard, HP C supports the following relationship between the remainder and division operators: a equals a%b + (a/b) * b for any integer values of a and b The result of a division or modulo division is undefined if the right operand is 0. The sign reversal or unary minus operator (-) multiplies its sole operand by -1. For example, if x is an integer with the value -8, then -x evaluates to 8. The result of the identity or unary plus operator (+) is simply the value of the operand. Refer to “Operator Precedence ” for information about how these and other operators evaluate with respect to each other. |
|