Operators in C are the symbol which performs various operations on operands such as addition, subtraction, multiplications, divisions or modulus, etc.

Operators in C

An operator performs various mathematical operations.
Operands are which on which operators performs these operations.
Operators in c perform operations and results stored into the variables (operands) as a result value of an expression.
C provides various operators which are as follows:

Types of Operators

  1. Arithmetic operators
  2. Increment and decrements operators
  3. Logical operators
  4. Bitwise operators
  5. Assignment operators
  6. Relational operators
  7. Cast operators

1. Arithmetic operators:

Arithmetic operators are used to performing various Arithmetic operations on operands. Arithmetic operators must have two operands.

Arithmetic operators are: + (addition), -(subtraction), *(multiplication) , /(division), %(modulus)

Example: a + b = c

2. Increment and decrements operators:

This operator used to add or subtract number by 1 Increment operator used to increment operand value by 1 and decrement operand used for decrements value by 1.We only require one operand for this.operator can be prefix or postfix that is written operand after and before operators.
Increment ++ , Decrement —

Prefix operators: In this, we write operators before the operands. That is value first increments before the result of an expression.

Postfix operators: In this, we write operators after the operands.that is value first increments after the result of an expression.
Example : a++;
–b;

3. Logical Operators

Logical operators used for performing logical operations such as Logical AND , Logical OR , Logical NOT.
Logical AND (&&): This operator returns true if both operands are non zero.
Logical OR(||): This operator returns true if either one of two operands are non zero.
Logical NOT(!): This operator used to make condition reverse that is if condition true it returns false.

4. Relational Operators

This operator used to check the relation between the two operands. Relational operators are as follow:
< Less than
> greater than
<= Less than equal to
>=greater than equal to
== equal to

5. Assignment Operators

This used for assigning the result to operand after expression solved. we assign the result to operands which is at left end. Assignment operators are as follow:
= equal to
+= Add and assign result to operand a+=b => a=a+b
-= subtract and assign result to operand a-=b => a=a-b
*= multiply and assign result to operand a*=b => a=a*b
/= divide and assign result to operand a/=b => a=a/b

6. Bitwise Operator

This performs on bit present in each byte of variable.bit can be 0 or 1. Bitwise operators are as follow:
~ one’s complements
<< left shift (Binary multiplication by 2)
>> Right shift (Binary divide by 2)

7. Cast Operators

This used to convert a value of operands to another type that is int to float or any type.
Example : float(10);

Operators program

//Arithmetic, Logical, Relational, Cast Operator

#include<stdio.h>
void main()
{

int no1,no2;
float no3;
no1=5; //Assignment operator
no2;10;
printf("Assignment operator executed and no1=%d\n",no1);
if(no1==5 && no2==10) {
printf("Logical AND operator executed\n");
}
if(no1<no2){
printf("Relational < operator executed");
}

no3=(float)no2;
printf("Cast operator executed no2=%f",no3);

}

Output

Operators in c
//Arithmetic operators and Increment and decrement operators.

#include<stdio.h>
void main(){
int no1,no2,add,sub,mul,div;
int inc,dec;
no1=10;
no2=10;
inc=2;
dec=2;
add=no1+no2;
sub=no1-no2;
mul=no1*no2;
div=no1/no2;


printf("addition=:%d\n",add);
printf("subtraction=:%d\n",sub);
printf("multiplication=:%d\n",mul);
printf("division=:%d",div);
printf("Postfix Increment=:%d\n",inc++);
printf("Prefix Decrements=:%d\n",--dec);
}

Output:
Operators in c

Write A Comment