Assignment Operators in C

The Assignment operators in C are some of the Programming operators that are useful for assigning the values to the declared variables. Equals (=) operator is the most commonly used assignment operator. For example:

int i = 10;

The below table displays all the assignment operators present in C Programming with an example.

C Assignment OperatorsExampleExplanation
=x = 25Value 25 is assigned to x
+=x += 25This is the same as x = x + 25
-=x -= 25This is the same as x = x – 25
*=y *= 25This is the same as y = y * 25
/=y /= 25This is the same as y = y / 25
%=y%= 25This is the same as y = y % 25

Assignment Operators in C Example

In this 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;
}
Assignment Operators in C Programming Language

The first printf statements will perform Programming Assignment operations on a and Total, and then the output of the result will be displayed. Let us see the Programming Optr functionality in this 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)