# Operators in C

Operators are symbols that help in performing operations of mathematical and logical nature.The classification of C operators are as follows

• Arithmetic
• Relational
• Logical
• Bitwise
• Assignment
• Conditional

Uses of Operators in C:-

The operators basically serve as symbols that operate on any value or variable. We use it for performing various operations- such as logical, arithmetic, relational, and many more. A programmer must use various operators for performing certain types of mathematical operations. Thus, the primary purpose of the operators is to perform various logical and mathematical calculations.

The programming languages like C come with some built-in functions that are rich in nature. The use of these operators is vast. These operators act as very powerful and useful features of all the programming languages, and the functionality of these languages is pretty much useless without these. These make it very easy for programmers to write the code very easily and efficiently.

1. Arithmetic Operators

C Arithmetic operators are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus in C programs.

Examples:-

```#include <stdio.h>

int main()
{
sub = a-b;
mul = a*b;
div = a/b;
mod = a%b;
printf("Subtraction of a, b is : %d\n", sub);
printf("Multiplication of a, b is : %d\n", mul);
printf("Division of a, b is : %d\n", div);
printf("Modulus of a, b is : %d\n", mod);
}```

Output:

`Addition of a, b is : 60Subtraction of a, b is : 20Multiplication of a, b is : 800Division of a, b is : 2Modulus of a, b is : 0`

2. Relational Operators

When we want to compare the values of two operands, then relational operators are used. If we want to check that is one operand is equal to or greater than other operands, then we use >= operator.

The below table lists of the relational operators in C with their functions.

Example:

```// Working of arithmetic operators
#include <stdio.h>
int main()
{
int a = 9,b = 4, c;

c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a divided by b = %d \n",c);

return 0;
}```

Output:

```a+b = 13
a-b = 5
a*b = 36
a/b = 2
Remainder when a divided by b=1```

3.Logical Operators

Logical Operators are used for True or False results.

Example:

```#include <stdio.h>

int main()
{
int a = 10, b = 4, c = 10, d = 20;

// logical operators

// logical AND example
if (a > b && c == d)
printf("a is greater than b AND c is equal to d\n");
else
printf("AND condition not satisfied\n");

// logical OR example
if (a > b || c == d)
printf("a is greater than b OR c is equal to d\n");
else
printf("Neither a is greater than b nor c is equal "
" to d\n");

// logical NOT example
if (!a)
printf("a is zero\n");
else
printf("a is not zero");

return 0;
}
```

Output:

`AND condition not satisfieda is greater than b OR c is equal to da is not zero`

4.Bitwise Operators:

During computation, mathematical operations like: addition, subtraction, multiplication, division, etc are converted to bit-level which makes processing faster and saves power.

Bitwise operators are used in C programming to perform bit-level operations.

5.Assignment Operators

These types of operators are used to assign a value to a variable.

Example:-

```// Working of assignment operators
#include <stdio.h>
int main()
{
int a = 5, c;

c = a;      // c is 5
printf("c = %d\n", c);
c += a;     // c is 10
printf("c = %d\n", c);
c -= a;     // c is 5
printf("c = %d\n", c);
c *= a;     // c is 25
printf("c = %d\n", c);
c /= a;     // c is 5
printf("c = %d\n", c);
c %= a;     // c = 0
printf("c = %d\n", c);

return 0;
}```

Output:

`c = 5 `
`c = 10c = 5c = 25c = 5c = 0`