OPERATOR: Operator is a symbol that perform any operation.
OPERAND: On which operation is to be performed.
EXAMPLE:
a+b Where + is an Operator and a, b are the Operands
C contains a rich set of operators. Operators used to perform basic airthmatic operations, manipulation of bits ,comparison etc. Operators operate on a single operand or two operands. C operators divided into 3 categories:
- Unary operators
- Binary operators
- Ternary operators
So Lets have a look on all Operators one by one:
TERNARY OPERATORS:
- It takes three operands.
- It is a conditional operator.
- The two symbols that is ? and : are used in ternary operator.
<Condition> | ? | <Value1> | : | <Value2> |
EXAMPLE:
M = a>b ? a : b;
Where Condition = a>b
Value1 = a
Value2 = b
Where Condition = a>b
Value1 = a
Value2 = b
If this condition a>b is True then a is assign to M but If condition is False then b is assign to M.
BINARY OPERATORS:
It takes two Operands. Binary operator are classified into 4 categories
- Airthmetic operators
- Logical operators
- Relational operators
- Bitwise operators
AIRTHMETIC OPERATORS:
These are used to perform the basic airthmatic operations such as multiplication,division,addition, substraction and Modulus Operator. It is used for finding remainder after an integer division. Operates on integer and float numbers. So there are two types of airthmetic operations:
- Integer airthmetic
- Floating point airthmetic.
INTEGER AIRTHMATIC:
If both the Operands are of integer type then Integer airthmetic is performed and result is integer value.
Ex:
If A=10 and B=20 then
- A+B=30
- B-A=10
- A*B=200
- B/A=2
FLOATING POINT AIRTHMATIC:
If both the Operands are of float type then Floating point airthmetic is performed and result is Floating point value.
Ex:
If A=1.5 and B=2.5 then
- A+B =4
- B-A=1
- A*B=3.75
- B/A=1
AIRTHMATIC OPERATORS:
OPERATIONS Addition Substraction Multiplication Division Modulus | OPERATOR + - * / % | PRECEDENCE 2 2 1 1 1 |
KEY POINTS ABOUT TABLE:
- Lowest Number Indicates Higher Priority.
- Highest Number Indicates Lowest Priority.
- Divide(/) Turncates the Fractional Part.
- Modulus Operator can not be used with Floating Point Number.
EXAMPLE:
If A=2 and B=5
- A+B=7
- B-A=3
- A*B=10
- B/A=2
- B%A=1
0 Response to "Detailed Discription of C Language Operators Section-1"
Post a Comment