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
Tag –
Assignment Operators in C
Latest posts by Mahesh Wabale (see all)
- Deployment of vault HA using MySQL - September 18, 2024
- Sending slack notification via pipeline job - August 25, 2024
- SonarQube integration with Jenkins - August 24, 2024