Professional Documents
Culture Documents
1. ARITHMETIC OPERATORS
Syntax form:
OPERAND OPERATOR OPERAND
X + Y
1. ARITHMETIC OPERATORS
• INTEGER DIVISION
• Dividing an integer by another integer will result in an
integer result.
• Thus 12/5 is 2 and NOT 2.4.
• Because integer cannot contain fractional part, a result
such as 2.5 cannot be obtained. In C++, the fractional part
of the result is dropped.
• To CAPTURE THE REMAINDER OF AN INTEGER DIVISION,
C++ provides a MODULUS OPERATOR (represented by
SYMBOL %) to be implemented only for integers.
• Thus 5 % 2 is 1.
OPERATORS
Example:
• Given int a=7, b=2;
• The following shows the memory content and the
result after the execution of the statement.
Total = 8 / 2 * 3 + 4 * 5 % 3;