C 赋值运算符C Assignment Operators

11/04/2016

作者

本文内容

赋值操作将右侧操作数的值分配给左侧操作数命名的存储位置。An assignment operation assigns the value of the right-hand operand to the storage location named by the left-hand operand.因此，赋值操作的左侧操作数必须是一个可修改的左值。Therefore, the left-hand operand of an assignment operation must be a modifiable l-value.在赋值后，赋值表达式具有左操作数的值，但不是左值。After the assignment, an assignment expression has the value of the left operand but is not an l-value.

C 中的赋值运算符可以在单个操作中转换值和赋值。The assignment operators in C can both transform and assign values in a single operation.C 提供了以下赋值运算符：C provides the following assignment operators:

运算符Operator

执行的操作Operation Performed

=

简单赋值Simple assignment

*=

乘法赋值Multiplication assignment

/=

除法赋值Division assignment

%=

余数赋值Remainder assignment

+=

加法赋值Addition assignment

-=

减法赋值Subtraction assignment

<<=

左移赋值Left-shift assignment

>>=

右移赋值Right-shift assignment

&=

按位“与”赋值Bitwise-AND assignment

^=

按位“异或”赋值Bitwise-exclusive-OR assignment

&#124;=

按位“与或”赋值Bitwise-inclusive-OR assignment

在赋值中，右侧值的类型将转换为左侧值的类型，在完成赋值后，该值将存储在左操作数中。In assignment, the type of the right-hand value is converted to the type of the left-hand value, and the value is stored in the left operand after the assignment has taken place.左操作数不得为数组、函数或常量。The left operand must not be an array, a function, or a constant.类型转换中详细介绍了依赖两个类型的特定转换路径。The specific conversion path, which depends on the two types, is outlined in detail in Type Conversions.