![]() |
| What is arithmetic operator in C ? |
Upon Completing this text you will be able to recognise:
- What is an arithmetic operators ?
- Different styles of arithmetic operator.
Arithmetic Operator in C:
C provide all the essential arithmetic operators,like addition(+),subtraction(-),multiplication(*),division(/) and modulo(%).these operators work as the same way as they to in other languages.These can be operate on any built-in data type allowed in C.
- Integer division(/) truncates any fractional part.
- The modulo division(%) operation produces the reminder of an integer division.
Types of Arithmetic Operator in C:
- Integer Arithmetic Operator
- Real Arithmetic Operator
- Mixed-Mode Arithmetic Operator
1.Integer Arithmetic Operator in C:
When both the operands in single arithmetic expression such as a+b are integers,then the expression is called an integer expression,and the operation is called integer arithmetic.Integer arithmetic always yields an integer value.
During integer division, if both the operands are of the same sign, the result is truncated towards zero.if both one of them is negative,the direction of truncation is implementation dependent.That is.
6/7=0 and -6/-7=0
but -6/7 may be 0 or -1.(machine dependent)
Similarly,during modulo division,the sign of the result is always the sign of the first operand(the dividend) that is
-15%3=-5
-15%-3=-5
15%-3=2
2.Real Arithmetic Operator in C:
Those arithmetic operation involving only real operands is called real arithmetic operator. The real operands may assume value either in decimal or exponential notation.Since floating point value are rounded to the number of significant digits permissible.That is
x=6.0/7.0=0.8571
y=2.22+2.22=4.44
z=-2.0/3.0=-0.666667
Note: The operator modulo(%) cannot be used with real operands
3.Mixed-mode Arithmetic Operator in C:
When one of the operands is real and the other is integer,the expression is called a mixed mode arithmetic expression and the operation is called mixed mode operation .
If either operand is of the real type, then only the real operation is performed and the result is always a real number.Thus
25/10.0=2.0
Conclusion:
In this article, I have explained the Arithmetic Operator in detail, hope that after reading this article, you will have any doubt left in the Arithmetic Operator, but still you have doubt, then definitely ask in the comment below.
