The Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Equals (=) operator is the most commonly used assignment operator in C. For example:
int i = 10;
The below table displays all the assignment operators present in C Programming with an example.
C Assignment Operators | Example | Explanation |
---|---|---|
= | x = 25 | Value 25 is assigned to x |
+= | x += 25 | This is same as x = x + 25 |
-= | x -= 25 | This is same as x = x – 25 |
*= | y *= 25 | This is same as y = y * 25 |
/= | y /= 25 | This is same as y = y / 25 |
%= | y%= 25 | This is same as y = y % 25 |
Assignment Operators in C Example
In this C assignment operators Program, We are using two integer variables a, Total, and their values are 7 and 21. Next, we are going to use these two variables to show you the working functionality of all the Assignment Operators in C Programming Language
#include <stdio.h> int main() { int a = 7; int Total = 21; printf(" Value of the Total = %d \n", Total += a ); printf(" Value of the Total = %d \n", Total -= a ); printf(" Value of the Total = %d \n", Total *= a ); printf(" Value of the Total = %d \n", Total /= a ); printf(" Value of the Total = %d \n", Total %= a ); return 0; }

The first printf statements will perform C Programming Assignment operations on a and Total and then the output of the result will be displayed. Let us see the C Programming Optr functionality in this C Program
Total += a means
Total = Total + a = 21 + 7 = 28
Total -= a => Total – a = 28 – 7 = 21
Total *= a => Total * a = 21 * 7 = 147
Total /= a => Total / a = 147 / 7 = 21
Total %= a => 21 % 7 = 0 (Remainder of 21/7 is = 0)