Assignment Operators in C –
C – Assignment Operators
There are different types of operators in C programming language, such as arithmetic, relational, bitwise, assignment, etc. The assignment operator is used to assign a value, variable and function to another variable. Let us discuss different types of assignment operators like =, +=, -=, /=, *= and %=. An assignment operator is used to assign a value to a variable. The most common assignment operator is =
Read Also – C – break statement in C programming
Example 3: Assignment Operators
Table of Operators in c
Operator | Example | Same as |
---|---|---|
= | a = b | a = b |
+= | a += b | a = a+b |
-= | a -= b | a = a-b |
*= | a *= b | a = a*b |
/= | a /= b | a = a/b |
%= | a %= b | a = a%b |
// 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 = 10 c = 5 c = 25 c = 5 c = 0
![types of operators in C programming](https://devopslover.com/wp-content/uploads/2024/01/image-58.png)
Tag –
Assignment Operators in C
Latest posts by Mahesh Wabale (see all)
- Sending slack notification via pipeline job - August 25, 2024
- SonarQube integration with Jenkins - August 24, 2024
- Deployment of 2 application java and python using k8s : slack alerting Using Jenkins pipeline liberary - August 10, 2024