# Operators in C

Last Updated Nov 1, 2015, 07:00:14 PM

`Operator` in computer program is like a symbol that instructs the compiler to perform mathematical operations

An operator is an object that is capable of manipulating a value or values. For example, in a methematical function like ` "3 + 5 "` integer values 3, and 5 are operands and ` + ` plus sign is an operator

C has wide range of operators that can perform different operations such as.

• Arithematic Operators
• Assignment Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Misc Operators

## Arithmatic Operators

An Arithmetic Operator is a mathematical function which takes two operands and perform different operations. The below table shows all the list of arithmetic operators available in c

Operator Description Example Try It Now
+ Performs addition of two numbers If `x = 2,y = 3` then ` x + y 5 `
- Subtract two numbers If `x = 4, y = 2 ` then `x - y = 2`
* Multiply two numbers If `x = 4, y = 2 ` then `x * y = 8`
/ Divide numerator by de-numerator If `x = 20, y = 2 ` then `x / y = 10`
% Modulus Operator If `x = 2, y = 20 ` then `x % y = 2`
++ Increment Operator If `x = 23 ` ? ` x++ = 24`
-- Decrement Operator If `x = 23 ` ? ` x-- = 22`

Here is an example program that demonistrates all the above arithematic operators

## Assignment Operators

An assignmentment operators is a operator which is used t assign a value to a variable, or an event. For example, ` int x = 3;` In this statement the value 3 is assigned to a variable x. Assignment operators are also used to perform logical operators such as boolean operands, integral operands

The below table lists all the assignment operators available in C programming.

Operator Description Example Try It Now
= (Assignment Operator) It is used to assign a value from right side operand to left side operand. If `x = 2 + 3` the total value of 2+3 will be assigned to the variable 'x'
+ = (Add AND Assignment Operator) It is used to add the right operand to the left operand and assign the result to the left If `z += y` then z becomes ` z = z + y`
- = (subtract AND Assignment Operator) It is used tosubtract the right operand to the left operand and assign the result to the left If `z -= y` then z becomes ` z = z - y`
* = (multiply AND Assignment Operator) It is used multiply the right operand with left operand and assign the result to the left operand If `z *= y` then z becomes ` z = z * y`
/= (divide AND Assignment Operator) It basically divides the left operand with right operand If `z /= y` then z becomes ` z = z / y`
%= (modulus AND Assignment Operator) It actually takes the modulus using two operands and assigns the result to the left If `z %= y` then z becomes ` z = z & y`
<<= Left shift AND assignment If `z <<= 44` is also can be write as ` z = z << 44`
>>= Right shift AND assignment If `z>>= 44` is also can be write as ` z = z >> 44`

## Relational Operators in C

Relational operators are used to compare two values and returns the result. Relational operators are also called as comparision operators

The below table lists all the available operators in c

Operator Description Example
== It is used to check if values of two operands are equal or not `(X == Y)` is not TRUE
!= It is used to check if two operands are equal or not `(X != Y)` is not TRUE
> It is used to check if the left operand is greater than the value of right operand `(X > Y)`
< It is used to check if the right operand is greater than the value of left operand `(X < Y)`
<= It is used to check if the value of left operand is less than or equal to the value of right operand `(X <= Y)`
>= It is used to check the value of left operand is less than or equal to the value of right operand `(X >=Y)`

## Logical Operators

Logical operators are used in decision making in computer programs. These operators are also sometiems called as boolean operators such as `AND, OR and NOT`

The below table lists all the assignment operators available in C programming.

Operator Description Example Try It Now
&& (AND) If both operands are true then only it becomes true (A && B ) if A and B are true then the result is TRUE
|| (OR) If any of the operand is true then only it becomes true (A || B ) if A OR B are true then the result is TRUE
! (NOT) It is used to reverse the logical state of its operand !(A && B ) is TRUE