Assignment Operators in C

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.

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

Assignment Operators in C Example

In this C 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

/* Program for Assignment Operators in C*/

#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

Below 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 Operator functionality

printf(" Value of the Total = %d \n ", Total += a );

Total += a means
Total = Total + a = 21 + 7 = 28

printf(" Value of the Total = %d \n", Total -= a );

Total -= a means
Total = Total – a = 28 – 7 = 21

 printf(" Value of the Total = %d \n", Total *= a );

Total *= a means
Total = Total * a = 21 * 7 = 147

 printf(" Value of the Total = %d \n", Total /= a );

Total /= a means
Total = Total / a = 147 / 7 = 21

printf(" Value of the Total = %d \n", Total %= a );

Total %= a means
Total = Total + a = 21 % 7 = 0 (Remainder of 21/7 is = 0)