Binary Operators In C Language

 

Binary Operators In C Language

If any operation perform on two operands is known as binary operators .These are classified into following types
  1. Arithmetic
  2. Assignment
  3. Relational
  4. Logical
  5. Bitwise
Arithmetic Operators : If any operation perform on Arithmetic values is known as arithmetic operators .These are classified into following types
OperatorExample
+ (Addition)a+b
- (Substruction)a-b
* (Multiplication)a*b
/ (Division)a/b
% (Modular Division)a%b
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,y,z;
printf("Enter x ,y values");
scanf("%d%d",&x,&y);
z=x+y;
printf("Addition is %d",z);
getch();
}
 


Assignment Operators : Assignment operators are used to assign the values to the variable or assign the variable to variable .These are classified into following types
OperatorExampleSame as
=a=ba=b
+=a+=ba=a+b
-=a-=ba=a-b
*=a*=ba=a*b
/=a/=ba=a/b
%=a%=ba=a%b
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,y;
printf("Enter x ,y values");
scanf("%d%d",&x,&y);
x=x+y;
printf("Addition is %d",x);
getch();
}
 


Relational Operators : Relational operators are used to check the relation between two variables .These are classified into following types
OperatorExample
==a==b
>a>b
<a<b
>=a>=b
<=a<=b
!=a!=b
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,y,z;
printf("Enter x ,y values");
scanf("%d%d",&x,&y);
z=x>y;
printf("The Relation of x>y is %d",z);
getch();
}
 
Nore :Relational operators are used in conditional statements only



Logical Operators : Logical operators are used to combine the morethan one condition .These are classified into following types
OperatorExample
Logical AND &&a>b && a>c
Logical OR ||a>b || a>c
Logical NOT !!(a>b && a>c)
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,y,z,p;
printf("Enter x , y, z values");
scanf("%d%d%d",&x,&y,&z);
p=(x>y && x>z);
printf("The Logical AND is %d",p);
getch();
}
 
Nore :Logical operators are used in conditional statements only


Bitwise Operators : Bitwise operators are used to perform any operation on binary values .These are classified into following types
OperatorExample
Bitwise AND &a&b
Bitwise OR |a|b
Bitwise CAP ^a^b
Bitwise NAGETION ~~a
Bitwise LEFT SHIFT <<a<<b
Bitwise Right SHIFT >>a>>b
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x,y,z;
printf("Enter x , y values");
scanf("%d%d",&x,&y);
z=x&y;
printf("The Bitwise AND is %d",z);
getch();
}



No comments:

Post a Comment