(9) What is Operator?
An expression is a combination of variable, constant and operator. The operator is used in expression to perform a task.For example:- 3x+7 Here ,
“3& 7” is a constant
“x” is a variable.
“+” is a operator of the above expression, which perform addition.
There are following types of operator
1. arithmetical operator (+, - , / , *)
2. relational operator ( < ,> , >=, <= , =, ! )
3. logical operator ( true or false)
arithmetical operator :- the operation which perform an
arithmetical operation (task) are called “ arithmetical operator” .
there are following types of arithmetical operator.
+ -------- plus.
- -------- minus.
* -------- multiplication.
/ ------- division.
% -------- remainder ( modulus),
Relational operator :- “>”----------- greater than.
“ <” ---------- less than.
“==”---------- equality.
“ >=” -------- greater than equal to.
“<” ---------- less than equal to.
“!=” --------- not equal to
When we require to compare the value present in
two variable in our program then we use the relational operator.
( > , < , ==, >= , <=)
It always return any one value as true or
false.
Example :- x=5, y=6
Equality(==) x==y
X=5, y=5 false
X==y True
Note:- “ =” assignment operator using this operator in a
program we assign a value to the variable as per our
requirement.
For example:- X=5
X=25%10
X=25+5
Logical operator:- The operator which allowed a user to make
a decision on two expression in a program then we use a logical
operator. It always return true or false.
And operator:-
It return true, if the expression present in both
side( left& right) at the operator return true, other wise return
false.
F and a = false.
F and t = false.
T and f = false.
T and t = true.
Expression
Example:- 4>5 AND 5>3-- expression 2
And is logical operator
F and T
False.
6>3 and 5>2
T and t
True
3>5 and 4>8
F and f
False.
C A B R=a>b S=a>c R and s
10 5 6 F F F
5 4 8 F F F
8 12 6 T T T
OR
It return true if the any one expression present in “ or”
operator return true it return false if the both al expression return
false.
Example
5>3 or 2>5 6>8 or 8>9
T or f f or f
True false.
C A B R=a>B S=a>c r. or s
10 25 6 T T T
5 2 4 F F F
3 5 6 F T t
NOT :-
It is a logical operator which is used to negate ( true
false& false to true) the values ( logical value) present in a
variable.
Example :-
A= true if y= false
Not a = false the not y true
Truth table :-
D A B C=a>b R=b>d C
and r C or
r Not
c Not r
10 5 15 F T F T F 12
12 8 4 T F f t F t
12 8 4 T F f t F t
Priority of operator :-
Solve this
(3+5)>(5+4) and (2-1)>5
8>9 and 1>5
f and f
f
now we can say from above example the first priority is
the arithmetic operation second and third priority is the
relational and logical operation respectively…………..
(5+3) > (4+5) AND (2-1)>5
8>9 AND 1>5
F and f
F
No comments:
Post a Comment