Multiplicative operators ('*', '/' and '%')

Previous Binary operators Next

There are three multiplicative operators in C:

* (multiplication: the product of the two operands)
/ (division: the quotient of the first operand divided by the second operand)
% (modulus: the remainder of the first operand divided by the second operand)
They use the following syntax:
expr1 * expr2
expr1 / expr2
expr1 % expr2
Note that '*' operator also has an unary form, and may be also used as a punctuator for creating pointer types.

Operands for '*' and '/' are of arithmetical type, and operands of '%' are of integral type. The usual arithmetic conversions are made on the operands. For '/' and '%', expr2 must be nonzero; expr2 == 0 results in an error (you can't divide by zero).

When expr1 and expr2 are integers and the quotient is not an integer:
  1. If expr1 and expr2 have the same sign, expr1 / expr2 is the largest integer less than the true quotient, and expr1 % expr2 has the sign of expr1.
  2. If expr1 and expr2 have opposite signs, expr1 / expr2 is the smallest integer greater than the true quotient, and expr1 % expr1 has the sign of expr1.
Note: Rounding is always toward zero.

Floating point multiplication and division are internally executed using the fmul and fdiv functions; more detailed info about rules of these operation is given with the description of these functions.