Operators,
Introduction
C supports a rich set of operator .We have already used several of them ,such as =,+,-,/,*,& and <,an operator is a symbol that tells the computer to perform certain mathematical or logical manipulation. Operator are used in programs to manipulate data and variable
C operator can be classified into a number of categories They include.
1.Arithmetic operator
2.Relational operator
3.Logical operator
4.Asignment operator
5.Increament and decrement operator
6.Conditional operator
7.Bitwise operator
8.Special operator
Arithmetic Operators.
C provides all basic arithmetic operator . They are listed in Table 3.1. The operator are +,-,*, and / all work the same way as they do in other language . These can operate on any built in data type allowed in C. The unary minus operator ,in effect ,multiplies its single operand by -1 therefore number preceded by a minus sign changes its sign.
Arithmetic Operator
Operator | Meaning |
+ | Addition |
– | Subtraction |
* | multiplication |
/ | Division |
% | Modulo division |
Integer division truncates any factorial part .The modulo division operators procedure The reminder of an integer division .Examples of use of arithmetic operators are:
a – b a + b
a * b a / b
a % b -a * b
Here a and b are variable and are known as operands .The modulo division operator % cannot be on floating point data. Older version of c does not supports unary plus but ANSI C supports.
Integer Arithmetic
When both the operands are in a single arithmetic expression such as a + b are integers, the expression is called an integer expression, and operation are called integer arithmetic .Integer arithmetic always yields an integer value
a – b = 10
a + b = 18
a * b = 56
a / b = 3
a % b = 2
Similarly ,during modulo division, the sign of the the result is the always sign of the first operand that is
-14 % 3 = -2
-14 % -3 = -2
14 % -3 = 2
Real Arithmetic
An arithmetic operation is involving is only real operand is called real arithmetic . Arial operand may assume value either in decimal or exponential notation . Since floating point values are reduced to the number of significant digit permission
x = 6.0 / 7.0 = 0.857143
y = 1.0/3.0 = 0.333333
z = -2.0 /3.0 = -0.666667
The operator % cannot be used with real operands. Mixed-mode arithmetic
When operands are real and other is integer , the expression called Mixed-mode arithmetic expression ,if either operands is of the real types , then only the real operation if performed and the result is always a real numbers.
Add comment