An arithmetic operator is a mathematical functionality that takes two operands and performs a calculation on them. They are used in common arithmetic calculation and most computer languages contain a set of such operators that can be used within equations to perform a number of types of sequential calculations.
In C language, there are five main arithmetic operators. Which are shown below:
|+||Addition||a+b||return addition of a and b|
|-||Subtraction||a-b||return the difference between a and b|
|*||Multiplication||a*b||a*b return the product of a and b|
|/||Division||a/b||return division of a and b|
|%||Modulus||a%b||perform division of a and b and return remainder|
These operators can operate on any built-in datatype in C programming. There is no exponentiation operator in C however you can use library function pow( ) to carry out exponentiation.
When an arithmetic operation is performed on two integers then such operation is called Integer arithmetic. It always gives an integer as the result.
Let us understand through a program:
In the integer division the fractional part truncated. Division gives the quotient, whereas modulus gives the remainder of division.
So, the output will be:
a=20 and b=10
value of cal is 30
value of cal is 200 now
value of cal is 10 now
value of cal is 3 now
value of cal is 2 now
But, when the arithmetic operation is performed on two floating point or real numbers, such operation is called floating point arithmetic.
So the output will be :
a=9.300000 and b=7.600000
value of cal is 16.900000
value of cal is 70.680000 now
value of cal is 1.700000 now
value of cal is 1.550000 now
The modulus operator is not applicable for floating point numbers.So that's why we didn't use that in the above program. If we use it for floating point calculation, then the program will raise an error. Let us understand this through a program:
The above program will raise an error
In function `main`.
`invalid operands to binary %`
Whenever we use one real operand and another integer operand and if the operation is arithmetic carried out on these two operands, then it is called mixed mode arithmetic.