Till now, we have been using the simple = value assignment operator. In fact, there are other value assignment operators, and they are all very useful. Except the = Operator, all other value assignment operators work in a similar way.
Like =, they all assign a value to the variable on the left Based on the operator and the right operand. The following table lists the operators and their descriptions.
Result of the example expression of the operator class
= Binary var1 = var2; var1 is assigned the value of var2
+ = Binary var1 + = var2; var1 is assigned the sum of var1 and var2
-= Binary var1-= var2; var1 is given the difference between var1 and var2
* = Binary var1 * = var2; var1 is given the product of var1 and var2
/= Binary var1/= var2; var1 is given the result of division between var1 and var2.
% = Binary var1 % = var2; var1 is given the remainder obtained by Division of var1 and var2.
We can see that these operators include var1 in the calculation process, the following code:
Var1 + = var2;
The result is the same as the following code.
Var1 = var1 + var2;
The + = operator can also be used as a string, the same as the + operator.
Using these operators, especially when using long variable names, makes the code easier to read.
This article is a new one. For more information, see the source and author!