Binary Operators in C Programming

Binary Operators in C Programming



Binary Operator
If any operation perform on two operands(variable) is known as binary operator.
In java language these opeatrs are classified into following types.

1.Arithmetic Operators
2.Assignment Operators
3.Relational Operators
4.Logical Operators
5.Bitwise Operators

Arithmetic Operators
These are the operands can be used to perform simple mathametical operation. Which are classified into following types.
Operator Operation Example
+ Addition x+y
- Substraction x-y
* Multiplication x*y
/ Division x/y
% Modular Division x%y
Write a C-program to print addition of two numbes

#include <stdio.h>
                                                                         
int main() {
    int x,y,z;
    printf("Enter x,y values");
    scanf("%d%d",&x,&y);
    z=x+y;
    printf("Addition is %d",z);
  
    return 0;
}
                                            

Output:

Enter x,y values12 12
Addition is 24

More Programs


Write a C-program to print addition of two numbes
Write a C-program to print subtraction of two numbes
Write a C-program to print multiplication of two numbes
Write a C-program to print division of two numbes
Write a C-program to print modular division of two numbes


Assignment Operators
Assignment operators are used to assign the values to the variable or assign the variable to variable There are classified into following types.
Operator Example Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y x=x%y

Write a C-program to print swaping of two numbers with using third variable
Write a C-program to print swaping of two numbers without using third variable


Relational Operators
Relational operators are used to check the relation between two variables. These are classified into following types
Operator Example
== x==y
< x<y
> x>y
<= x<=y
>= x>=y
!= x!=y
Write a C-program to print relation of two numbers


Logical Operators
Logical Operators are used to combine the morethan one condition. These are classified into following types.
Operator Example
&& x>y && x>z
|| x>y || x>z
! !(x>y && x>z)

!(x>y || x>z)

!(x>y) && !(x>z)

!(x>y) || !(x>z)
Write a C-program to print logical operators program using &&, || ,!


Bitwise Operators
Bitwise Operators are used to perform any operaion on binary(0 and 1) values.These are classified into following types
Operator Operation Example
& AND x&y
| OR x|y
^ CAP x ^ y
~ NAGETION ~x
<< LEFT SHIFT x<<y
>> RIGHT SHIFT x>>y
Write a C-program to print bitwise AND operation

#include <stdio.h>
                                                                         
int main() {
    int x,y,z;
    printf("Enter x,y values");
    scanf("%d%d",&x,&y);
    z=x & y;
    printf("\n Bitwise AND is:  %d",z);
    
    return 0;
}
                                            

Output:

Enter x,y values 10 15
Bitwise AND is: 10

More Programs


Write a C-program to print bitwise AND operation
Write a C-program to print bitwise OR operation
Write a C-program to print bitwise CAP operation
Write a C-program to print bitwise NEGATION operation
Write a C-program to print bitwise LEFT SHIFT operation
Write a C-program to print bitwise RIGHT SHIFT operation