Table of Contents
Operator:-
- Operator is a symbolic name which is used to manipulate data.
- It is the symbol use to perform calculation.
- It perform to operand.
- EX:- +,- ,* ,% ,/ ,&
Types of operator:-
There are two types of operator
1.According to operand:-
- Operand is the value on which the operator perform the calculation.
- EX:- See the upper image
2.According to operand there are three types of operator.
A. Unary operator:-
- Operator that takes only one value is called as unary operator.
- EX:-Negation operator(-),increment(++),Decrement(–)
B. Binary operator:-
- Operator that takes two value is called as Binary operator.
- EX:- + ,- , * ,< ,>,
C. Ternary Operator:-
- Operator that take three value is called as Ternary Operator.
- EX:-Conditional operator(?)
2.According to the calculation:-
- On the basic of calculation there are following types of operator.
[i] Arithmetic operator
[ii] Bitwise operator
[iii] Conditional operator
[iv] Decrement & Increment operator
[v] Logical operator
[vi] Assignment operator
[vii] Relational operator
[viii] Special operator
a. Comma(,) operator
b. Size of() operator
[I] Arithmetic operator:-
- This operator is used to perform arithmetic operator.
operator | Meaning | Example | Result |
+ | Addition | 20+2 | 22 |
– | Subtraction | 20-2 | 18 |
* | Multiplication | 20*2 | 40 |
/ | Division | 21/2 | 10 |
% | Remainder | 21%2 | 1 |
[ii] Bitwise operator:-
- This operator is used to perform operation at binary digit level.
operator | Meaning |
<< | Shift the bit to Left |
>> | Shift the bit to Right |
~ | One’s compliment |
| | Logical Bitwise OR |
& | Logical Bitwise AND |
⩒ | Logical Bitwise EX-OR |
[iii] Conditional operator:-
- This operator is used to check a condition and select a value depending on the value of condition.
SYNTAX:-
Variable=(condition)? value1: value2,during the operation if condition be true. It gives value1 as output otherwise it gives value2 output.
EX:-
INT a=7 b=10 , C
1st (a<b)? a:b,
c=7
2nd c=(a>b)?a:b,
c=10
[iv] Decrement & Increment operator:-
A. Decrement operator:-
- This operator is used to reduced the value of integer variable by 1(one)
- It is denoted by(–)
- There are two types of decrement operator.
a. Predecrement operator:- This operator is used to reduce the value of variable before calculation.
EX:-
INT a=7 b=8 C
(i) C=(–a)+b
=6+8 =14
(ii) c= (–a)+(–b)
= 6+7
=13
b. Post-Decrement:- This operator is used to reduce the value of variable after calculation by 1(one).
EX:-
INT a=6 b=3 C,
C=(a–)+(b–)
=6+3
=9
Hance
a=5
b=2
B. Increment operator:-
- This operator is used to increase the value of integer variable by one
- It is denoted by(++)
- There are two types of increment operator.
a. Pre-increment operator:- This operator is used to increase the value of of variable before calculation by 1(one).
EX:- INT a=5 , b=3 C,
C=(++a)*(++b)
C=6*4
=24
b. Post-increment:- This operator is used to increase the value of variable after calculation by1(one).
EX:-
a=7 ,b=4 C,
C=(a++)-(b++)
=7-4
=3
Hance
a=7
b=5
[v] Logical operator
- This operator is used to perform logical operation.
operator | Meaning | Example | Result |
&& | Logical AND | (14>2)&&(14<2) | F |
|| | Logical OR | (14>2)||(14<2) | T |
! | Logical NOT | !(14<2) | T |
[VI]Assignment operator
- Assignment operator are used to perform arithmetic operation while assigning a value to a variable.
operator | Example | Condition(M=20) | Result |
+= | M+=10 | M=M+10 | 30 |
-= | M-=10 | M=M-10 | 10 |
*= | M*=10 | M=M*10 | 200 |
/= | M/=10 | M=M/10 | 2 |
%= | M%=10 | M=M%10 | 0 |
[Vii] Relational operator:-
- This operator is used to compare the value of the operands.
operator | Meaning | Example | Result |
< | less than | 5<2 | F |
> | Greeter than | 7>2 | T |
<= | less than or equal | 5<=2 | F |
>= | Greeter than or equal | 5>=2 | T |
== | Equal | 4==2 | F |
!= | Not equal | 4!=2 | T |
[Viii] Special operator
a. Comma(,) operator:-
- This operator is used to separate two variable, expression
- EX:- INT a,b,c
b. Size of () operator:-
- This operator is used to find the size of data type in this memory.
- EX:-INT a,b
- Float p,q
- Char x,y,z
HERE:-
a=size of(x)=1 Byte
b=Size of (p)=4 Byte
Relate link
Thanks