Assignment Operator
The assignment operators are used to assign the value to a variable. The general expression syntax:
Variable = expression;
(left part) (right part)
First at all the expression at the right part is evaluated and the resultant value is assigned to the variable at the left part. In addition to simple assignment operator, there are some other assignment operators called compound assignment operators.
Example:
a + = 1;
+ = is a compound assignment operator. It first adds one to the current value of variable a and then assigns this new value to a. There are several compound assignment operators available in C , + =, - =, * =, / =, % =, etc.
Example:
a + = 1 is same as a = a + 1
a - = 4 is same as a = a - 4
a * = (b + d) is same as a = a * (b + d)
a / = (n + 1) is same as a = a / (n + 1)
a % = 10 is same as a = a % 10
The use of shorthand assignment opertors has three advantages:
1. What appers on the left hand side need not be repeated and therefore it becomes easier to write.
2. The statement is more concise and easier to read.
3. The statement is more effiecient.