Arithmetic operators may be combined with the assignment operator to obtain composite assignment operators. An arithmetic operator is written first followed by the assignment operator but not vice versa. In all the composite operators there should not be any blank space between the symbols. For instance, in+= if we give space between+ and= (suchas+ =),it may result in an error.
The statement A += 6; implies add 6 to the present value of A and assign the result to A'. So, it is equivalent to the following statement:
A= A + 6;
Similarly, the statement A /= 4; is equivalent to the following statement:
Other composite operators can be similarly dealt with.
Illustrates the application of composite assignment operators.
void main ()
int A=5, B=10, P=8, S = 20, T = 30;
A += 3;
B *= 2;
P -= 4;
printf("A =%d\tB = %d\tP = %d\tS = %d\n", A, B, P, S);
printf("T = %d\n", T );