There are five arithmetic operators in C .
They are:-
They are:-
Operator | Purpose |
÷ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Remainder after integer division. |
The operator % is known as the modulus operator
e.g. Suppose that a and b are integer variables whose values are 10 and 3 respectively, several arithmetic expressions involving these variables are shown below together with their resulting values
Expression | Value |
a÷b | 13 |
a - b | 7 |
a * b | 30 |
a / b | 3 |
a % b | 1 |
Now suppose that v1 and v2 are floating - point variables whose values are 12.5 and 2.0 respectively. several arithmetic expressions involving these variables are shown below, to- gether with their resulting values
Expression | Value |
v1 ÷ v2 | 14.5 |
v1 - v2 | 10.5 |
v1 * v2 | 25.0 |
v1 / v2 | 6.25 |
Now suppose c1 and c2 are character - type variables that represent the characters P and T, respectively. Several arithmetic expression that make use of these variables are shown be- low together with their resulting values (based upon the ASCII character set)
Expression | Value |
Cl | 80 |
Cl + C2 | l64 |
Cl + C2 +5 | l69 |
Cl + C2 +'5' | 2l7 |
P is encoded as (decimal ) 80, T is encoded as 84, and 5 is encoded as 53 in the ASCII character set, as shown above.
Suppose that a and b are integer variables whose values are 11 and - 3, respectively. Several arithmetic expressions involving these variables are shown below, together with their result- ing values
Expression | Value |
a+b | 8 |
a-b | l4 |
a*b | -33 |
a/b | -3 |