Assignment operators are used to assign the result of an expression to a variable.we have seen the usual assignment operator ‘=’.
Sr.No |
Operators |
Example |
---|---|---|
01 |
+= |
a += 1 |
02 |
-= |
a -= 1 |
03 |
*= |
a *= n+1 |
04 |
/= |
a /= n+1 |
05 |
%= |
a %= b |
#include
int main() {
int values;
values = 10;
values += 1;
printf("\nValues is = %d", values);
values = 10;
values -= 1;
printf("\nValues is = %d", values);
values = 10;
values *= 2;
printf("\nValues is = %d", values);
values = 11;
values /= 4;
printf("\nValues is = %d", values);
values = 11;
values %= 4;
printf("\nValues is = %d", values);
return 0;
}
Values is = 11
Values is = 9
Values is = 20
Values is = 2
Values is = 3