C - OPERATORS

In this chapter will understand types of Operators used in C.

What are operators in C ?

Operators are used to perform mathematical and logical operations. For example, +, -, /, *, % etc are Operators.

Different types of Operators in C

• Arithmetic operators

• Logical operators

• Assignment operator

• Relational operators

• Bitwise operators

Arithmetic operators

+, -, *, /, %, ++ and -- are the arithmetic operators. For example let’s say we have two variables X and Y with values 10 and 2 respectively, then

Arithmetic operator
```/* X = 10 and Y = 2 */
X + Y = 12 (addition)
X - Y = 8(subtraction)
X * Y = 20(multiplication)

X / Y = 5(Division)

X % Y = 0(Modulas gives remainder)

X++ = 11(increment variable by 1)

Y++ = 3(called as increment operator)

X-- = 9(decrement variable by 1)

Y-- = 1(called as decrement operator)
```

Logical operators

In C, &&(AND), ||(OR) and !(NOT) Are the logical operators which returns either true or false. The ! Operator have only one operands. If we have two variables X and Y such that x = 1(true) and y = 0(false) then

```X && Y Will return false

X || Y Will return true

!X will return false and

!y will return true```

How Logical operators works?

&& Operator will return true only if both the operands are true, which in our case x was true but y was false.

|| Operator will return true when either of the two operands are true, in other words when both the operands are false, || will return false. Hence X || Y is true

The ! operator results the opposite of the variable, so when X is true !X will be false and when X is false !X will be true.

Assignment operator

Assignment operator are used to assign values to a variable. For example, `x = 100;` Here 100 is the value assigned to variable x using `=` operator.

Bitwise operators

These operators works on bits. They perform bit by bit operations that’s why they are known as bitwise operators.

In the next chapter, We will about operators.