Operator is a symbol which operates on operand.
Example 3+2. Here 3 and 2 is called operand and + is called operator .
On the basis of operand operators are three types.
- Unary operator
- Binary operator
- Ternary operator
- Arithmetic operator
- Modular division operator
- Increment/decrement operator
- Relational operator
- Logical operator
- Bitwise operator
- Assignment operator
- Conditional operator
* && Logical operator
* || Logical operator
* ! Logical not operator
Logical and operator:&&
This is a binary operator .If both
the operands are true then it return true or 1 otherwise it return false or 0.
A |
B |
A&&B |
1 |
1 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
Truth
table for logical and operator
#include<stdio.h>
main( )
{
int a=10,b=52,c=0;
c=a&&b;
printf("%d",c);
}
Ans=1
Logical OR operator: | |
It is also a binary operator that
means having two operand, if both the operand are 0 or false then it return
false or 0 otherwise it return 1 or true.
A |
B |
A||B |
1 |
1 |
1 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
0 |
Truth table for logical or operator
LOGICAL NOT operator: !
It
is a unary operator that means it has a single operand .The operation of this
operator is convert true to false and vice versa.
A |
!A |
1 |
0 |
0 |
1 |
#include<stdio.h>
main( )
{
int a=9,b=10,c=0;
c=!(a>b);
printf("%d",c);
}
Ans=1
These are binary operator one which is
an unary opeartor . The operation of
this operator is to manipulation on bitwise register data therefore here the
operand must be of integer or character type. These operators are:
~
Bitwise compliment operator
& Bitwise and operator
| Bitwise or operator
^ Bitwise xor operator
<< Bitwise left shift operator
>> Bitwise right
operator
~ (Bitwise compliment operator):
It is an
unary operator . The operation of this operator is to convert the binary
register data 1 to 0 and 0 to1.
main ()
{ int a=5,b;
b=~a;
printf
(“%d”,b); outputis-6
}
|
|
|
|
|
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
0 |
(Bitwise And operator)&
This is a
binary operator .The operation of this opertor is to manipulate on binary
register data of two operand bit by bit .If bit value of the both operands are
one then it returns 1 otherwise it returns 0.
A |
B |
A&B |
1 |
1 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
#include<stdio.h>
main()
{
int a=5,b=3,c=0;
c=a&b;
printf("%d",c);
}
ans=1
A |
1 |
0 |
1 |
B |
0 |
1 |
1 |
A&B |
0 |
0 |
1 |
(Bitwise OR operator)|
It is a binary operator .
it is also operates on binary register data bit by bit . if the both the
operands bit value is 0 then returns 0.other wise it is return 1.
A |
B |
A|B |
1 |
1 |
1 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
0 |
main ()
{
int a=5,b=3,c;
c=a|b;
printf(“d%”,c);7
}
A |
1 |
0 |
1 |
B |
0 |
1 |
1 |
A|B |
1 |
1 |
1 |
^(Bitwise
Xor operator)
Itr is a binary operator . it is also
operates on binary register data bit by bit.if the both the operands bit value
is 0or 1it returns 1. Otherwise it is return 0.
A |
B |
A^B |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
0 |
main ()
{
int a=5,b=3,c;
c=a^b’;
printf(“d%”,c); 6
}
A |
1 |
0 |
1 |
B |
0 |
1 |
1 |
A^B |
1 |
1 |
0 |
<<
(BITWISE LEFT SHIFT OPERATOR)
This is also a binary operator. The
operation of this operator is shift binary register data from right to left. In
this process every time one bit of data is shifted at a time.
Syntax:-data << No of bit shifted
main ()
{
int a = 5, b;
b= a << 2;
print (“%d”, b);
}
formula (Data * 2no of bit
shifted)
>>
(BITWISE RIGHT SHIFT OPERATOR)
This is also a binary operator. The
operator of this operator is shift binary register data from left to right . In
this process every time one bit of data is shifted at a time .
Syntax :-
data << No of bit shifted
main ()
{
int a= 20 ,b=0;
Print (“%d”,b);
}
formula ( Data /2no of bit shifted)
These are binary operator .The operation of
this operator is to assign the right side value on the left side variable,
after a specified operation .These operators are:-
=: equal, -=: minus equal, *=: multiplication equal
+=: plus equal /=: division equal %=: M division equal
N: B Write
some common example program on this Assignment operator.
main ()
{ int a=5, b=10;
a +=b /* here a and b add with
each other Then addition value on a */
Print (“%d %d”, a, b); output is a =15, b=10
}
main ()
{ int a=5, b=10;
a-=; /*here a and b subtract
with each other Then assign the subtraction value on a*/
Print (“%d %d”, a, b);
output is a=-5, b=10
} etc.
No comments:
Post a Comment