c语言复合赋值运算符_复合赋值运算符

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语言复合赋值运算符

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值