- += Compound Addition Operator
- -= Compound Subtraction Operator
- %= Compound Modulo Operator
- *= Compound Multiplication Operator
- /= Compound Division Operator
These operators combine an assignment and an arithmetic operator. The operators display similar patterns, but, of course, they use their own respective logic and rhythmic symbols. Scroll down for some examples.
Examples of Compound Operators:
+= Compound Addition Operator
In the below example, we are taking the original value of num, which is 5 and we are adding 10 to it, which is 15.
-= Compound Subtraction Operator
We give num2 a value of 10 and then we use the operator with the value of 10, and, since we’re subtracting, we end up with the value of 0.
%= Compound Modulo Operator
We have a variable titled num3 and we give it a value of 50 and then we use the operator with a value of 9 and the remainder is 5 and that’s our output.
*= Compound Multiplication Operator
We give num4 a value of 4, use the operator with a value of 9 and this outputs a value of 45.
/= Compound Division Operator
Our operator is num5 with a value of 50, we then use the operator with a value of 25 which outputs 2.