Compartilhar via


C Assignment Operators

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.

Syntax

  • assignment-expression:
    conditional-expression

    unary-expression assignment-operator assignment-expression

  • assignment-operator: one of
    =   *=   /=   %=   +=   –=   <<=   >>= &=   ^=   |=

The assignment operators in C can both transform and assign values in a single operation. 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

|=

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.

See Also

Reference

Assignment Operators