# C Operators

Like other programming languages, C language also supports the set of operators to perform a different kind of operations on variables.
Now, the question arises, What is Operator?

### Operator

An Operator is defined as a symbol that represents some mathematical or logical operations. It can take one or more operands to perform its operations.
For example, Arithmetic Operators perform Arithmetic operations such as Addition(+) Operator performs the addition operation.

### Operand

Operands are the variables or objects which are used by Operators to evaluate the expression or operation.
For example: ‘y + x’ is an expression, where ‘x’ and ‘y’ are operands and ‘+’ is an Operator. All expressions must have at least one operand.

### Types of Operators

The operators can be classified like this:

1. Arithmetic Operators
2. Relational or Comparison Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Misc/Special Operators

Now, we are gonna learn about all these operators one by one.

### Arithmetic Operators

An Arithmetic Operator performs some mathematical operations such as addition, subtraction, multiplication, and division.

Here is the table of following Arithmetic Operators which are supported by C language:

###### For example:
``````#include
int main()
{
int x=1;
int y=5;
int result=x+y;
printf("sum of 5 and 1 is %d",result);
return 0;
}
﻿``````

### Relational Operators :

Relational Operators check whether the relation between two or more operands is True or False.

Here, you can see all the relational operators supported by C with the help of the given table.
Assuming that the variable A holds 10 and variable B holds 20 then −

###### For example:
``````#include<stdio.h>
int main()
{
int x=1;
int y=5;
int result=x<y;//This checks wether the condition is true or not
printf("Result %d",result);//If the condition is true, this will print 1 otherwise 0 means false.
return 0;
}``````

### Logical Operators

Logical Operators are mainly used to control program flow. The concepts of logical operators are simple. Logical Operators allow a program to make a decision based on multiple conditions. Each operand is considered a condition that can be evaluated to a true or false value. Then the value of the conditions is used to determine the overall value.

Here is the table of all Logical Operators supported by C language:
We considered that variable A holds 1 and variable B holds 0, then –

###### For example:
``````#include<stdio.h>
int main()
{
int x=1;
int y=5;
int result=(x<y)||(x>y);//Logical OR Operator
printf("result= %d",result);
return 0;
}``````

### Bitwise Operators

A Bitwise Operator used to perform bitwise operations on bit patterns. Unlike common logical Operators, which work with bytes, Bitwise Operators can check wor set each of the individual bits within a byte.

If the corresponding bits of two operands is 1, then the output of bitwise AND is 1. If either bit of an operand is 0, the result of the corresponding bit is evaluated to 0.

Decimal values are converted into binary values which are the sequence of bits and bitwise Operators work on these bits.

### Bitwise operators in C language are

• & (bitwise AND)
• | (bitwise OR)
• ~ (bitwise OR)
• ^ (XOR)
• << (left shift)
• >> (right shift).

TRUTH TABLE FOR BITWISE OPERATION & BITWISE OPERATORS:

###### For example:
``````#include
int main()
{
//consider x and y equal to 40 and 80 respectively, then the binary valur of x and y will be
int x=00101000;
int y=01010000;
int result=x&y;//Bitwise AND Operator
printf("Result= %d",result);//Answer will be 00000000(in binary) and 0(in decimal).
return 0;
}``````

### Assignment Operators

With the help of Assignment Operators, we can assign a new value to a variable.
The following table lists the assignment operators supported by the C language:

###### For example:
``````#include
int main()
{
int x;
x=1;
x+=5;//This is an Addition Assignment Operator
printf("x= %d",x);
return 0;
}
﻿``````

### Misc/Special Operators

We have been gone through to most of the operators supported by C language. Besides these Operators discussed above, here are some other important operators including size and? : supported by the C Language.

###### For example:
``````#include
int main()
{
int x=1;
int y;
y=sizeof x;
printf("y= %d",y);
return 0;
}``````