The operands acted upon by arithmetic operators must be numeric values (int, float, etc.).
The division operator requires that the second operand be non-zero.
Integer division truncates any fractional part.
The modulo division operator (remainder operator) requires that both operands be integers and that the second operand be non-zero.
The unary minus operator multiplies its single operand by -1.
Integer Arithmetic, Real Arithmetic, and Mixed-mode Arithmetic
When both the operands in a single arithmetic expression such as a+b are integers, the expression is called an integer expression, and the operation is called integer arithmetic.
An arithmetic operation involving only real operands is called real arithmetic.
When one of the operands is real and the other is an integer, the expression is called a mixed-mode arithmetic expression.
Note:-
Integer arithmetic always yields an integer value.
The operator % cannot be used with real operands.
For Integer Division, when both operands are of the same sign, the result is truncated towards 0.
E.g. 6/7=0 and -6/-7=0.
However, when one of the operands is negative, then the truncation is machine-dependent i.e. -6/7 maybe 0 or -1.
For modulo division, the sign of the result is always the sign of the first operand (the dividend).
E.g. -14 % 3 = -2
-14%-3 = -2
14 % -3 = 2
Division Rule for Integer Arithmetic, Real Arithmetic and Mixed-mode Arithmetic
1. int / int = int
2. float / float = float
3. int / float = float
4. float / int = float
Some Examples
#include
#include
void main()
{
int months, days;
clrscr();