c语言复合赋值运算符
Compound-assignment operators provide a shorter syntax for assigning the result of an arithmetic or bitwise operator. They perform the operation on the two operands before assigning the result to the first operand.
复合分配运算符为分配算术运算符或按位运算符的结果提供了较短的语法。 在将结果分配给第一个操作数之前,它们先对两个操作数执行运算。
Java中的复合赋值运算符 ( Compound-Assignment Operators in Java )
Java supports 11 compound-assignment operators:
Java支持11种复合赋值运算符:
+= assigns the result of the addition.
-= assigns the result of the subtraction.
*= assigns the result of the multiplication
/= assigns the result of the division.
%= assigns the remainder of the division.
&= assigns the result of the logical AND.
|= assigns the result of the logical OR.
^= assigns the result of the logical XOR.
<<= assigns the result of the signed left bit shift.
>>= assigns the result of the signed right bit shift.
>>>= assigns the result of the unsigned right bit shift.
用法示例 ( Example Usage )
To assign the result of an addition operation to a variable using the standard syntax:
使用标准语法将加法运算的结果分配给变量:
//add 2 to the value of number
number = number + 2;
But use a compound-assignment operator to effect the same outcome with the simpler syntax:
但是,使用复合赋值运算符以更简单的语法实现相同的结果:
//add 2 to the value of number
number += 2;
翻译自: https://www.thoughtco.com/compound-assignment-operator-2034054
c语言复合赋值运算符