[Main]
Title=Multiplicative operators ('*', '/' and '%')
Index=*, /, %

[Top]
There are three multiplicative operators in C:
<PRE>* (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)
</PRE>
They use the following syntax:
<PRE><I>expr1</I> * <I>expr2</I>
<I>expr1</I> / <I>expr2</I>
<I>expr1</I> % <I>expr2</I>
</PRE>
Note that '*' operator also has an <A HREF="$$LINK(unarypm)">unary form</A>, and may be also
used as a punctuator for creating <A HREF="$$LINK(asterisk)">pointer types</A>.
<BR><BR>
Operands for <CODE>'*'</CODE> and <CODE>'/'</CODE> are of arithmetical type, and operands of
<CODE>'%'</CODE> are of integral type.
The usual arithmetic conversions are made on the operands.
For <CODE>'/'</CODE> and <CODE>'%'</CODE>, <I>expr2</I> must be nonzero;
<I>expr2</I>&nbsp;==&nbsp;0 results in an error (you can't divide by zero).
<BR><BR>
When <I>expr1</I> and <I>expr2</I> are integers and the quotient
is not an integer:
<OL>
<LI>
If <I>expr1</I> and <I>expr2</I> have the same sign,
<I>expr1</I>&nbsp;/&nbsp;<I>expr2</I> is the largest integer less
than the true quotient, and <I>expr1</I>&nbsp;%&nbsp;<I>expr2</I>
has the sign of <I>expr1</I>.
</LI>
<LI>
If <I>expr1</I> and <I>expr2</I> have opposite signs,
<I>expr1</I>&nbsp;/&nbsp;<I>expr2</I> is the smallest integer greater
than the true quotient, and <I>expr1</I>&nbsp;%&nbsp;<I>expr1</I> has
the sign of <I>expr1</I>.
</LI>
</OL>
<B>Note:</B> Rounding is always toward zero.
<BR><BR>
Floating point multiplication and division are internally executed using the
<A HREF="$$LINK(timath.h/fmul)">fmul</A> and <A HREF="$$LINK(timath.h/fdiv)">fdiv</A> functions; more detailed
info about rules of these operation is given with the description of these functions.
