# Assignment Operators in C  Written by Shuvhojit DebFebruary 7, 2022
C
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE Shuvhojit Deb

Full Stack Developer

## Assignment Operator in C

There are different kinds of the operators, such as arithmetic, relational, bitwise, assignment, etc., in the C programming language. The assignment operator is used to assign the value, variable, and function to another variable. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *=, and %=.

Example of the Assignment Operators:

A = 5; // use Assignment symbol to assign 5 to the operand A

B = A; // Assign operand A to the B

B = &A; // Assign the address of operand A to the variable B

A = 20 \ 10 * 2 + 5; // assign equation to the variable A

## Different List of Assignment Operators in C

Below is the list of Assignment operators in C

1. The simple assignment operator (=): This operator Assigns values from the right operands to the left operand.

2. Add AND operator (+=): This operator adds the right operand to the left operand and assigns the output to the left operand.

3. Subtract AND operator (-=): This operator subtracts the right operand from the left operand and assigns the result to the left operand.

4. Multiply AND operator (*=): This operator multiplies the right operand with the left operand and assigns the result to the left operand.

5. Divide AND operator (/=): This operator divides the left operand with the right operand and assigns the result to the left operand.

6. Modulus AND operator (%=): This operator takes modulus using two operands and assigns the result to the left operand.

There are many other assignment operators such as Left shift AND (<<=) operator, Right shift AND operator (>>=), Bitwise AND assignment operator (&= ), Bitwise exclusive OR and assignment operator (^=), Bitwise inclusive OR and assignment operator(|=)

## Example of the Assignment Operators

### Example #1

Program to implement the use of = operator:

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y, total;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`printf("Enter the value of Y: ");`
`scanf("%d",&Y);`
`total = X + Y;`
`printf("%d", total);`
`return 0;`
`}`

Output:

### Example #2

Program to implement the use of Add AND operator (+=) in C:

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`printf("Enter the value of Y: ");`
`scanf("%d",&Y);`
`Y += X;`
`printf("%d", Y);return 0;`
`}`

Output:

### Example #3

Program to use Subtract AND operator (- =) in C:

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`printf("Enter the value of Y: ");`
`scanf("%d",&Y);`
`Y -= X;`
`printf("%d", Y);return 0;`
`}`

Output:

### Example #4

Program to use Multiply AND operator (*=) in C:

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`printf("Enter the value of Y: ");`
`scanf("%d",&Y);`
`Y *= X;`
`printf("%d", Y);`
`return 0;`
`}`

Output:

### Example #5

Program to use Divide AND operator (/=) in C:

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`printf("Enter the value of Y: ");`
`scanf("%d",&Y);`
`Y /= X;`
`printf("%d", Y);`
`return 0;`
`}`

Output:

### Example #6

Program to use Modulus AND operator (%=) in C

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`printf("Enter the value of Y: ");`
`scanf("%d",&Y);`
`Y %= X;`
`printf("%d", Y);`
`return 0;`
`}`

Output:

### Example #7

Program to use Left shift AND (<<=) operator in C

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`X <<= 2;`
`printf("%d", X);`
`return 0;`
`}`

Output:

### Example #8

Program to use Right shift AND (>>=) operator in C

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`X >>= 2;`
`printf("%d", X);`
`return 0;`
`}`

Output:

### Example #9

Program to use Bitwise AND assignment operator (&= ) in C

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`X &= 2;`
`printf("%d", X);`
`return 0;`
`}`

Output:

### Example #10

Program to use Bitwise exclusive OR and assignment operator (^=)

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`X ^= 2;`
`printf("%d", X);`
`return 0;`
`}`

Output:

### Example #11

Program to use Bitwise inclusive OR and assignment operator (|=) in C

Code:

`#include<stdio.h>`
`#include<conio.h>`
`int main()`
`{`
`int X, Y;`
`printf("Enter the value of X: ");`
`scanf("%d",&X);`
`X |= 2;`
`printf("%d", X);`
`return 0;`
`}`

Output:

Assignment Operator
C Language
Program
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE     You must be Logged in to comment
Code Block Shuvhojit Deb
Full Stack Developer  117 Blog Posts
Trending Technologies
15 Software40 DevOps48 Frontend Development24 Backend Development20 Server Administration17 Linux Administration26 Data Center24 Sentry24 Terraform23 Ansible83 Docker70 Penetration Testing16 Kubernetes21 NGINX20 JenkinsX17
Recommended Blogs
8        8 Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Anik Adhikary Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.