The assignment operator in C is used to assign a value to a variable. The left side operand of the assignment operator is a variable, and the right side operand is a value of the same data type as the variable on the left side. The simplest assignment operator is the "=" operator, which assigns the value on the right to the variable on the left. Other types of assignment operators include:
- Add and Assign Operator (+=): This operator adds the left side operand to the right operand and then assigns the result to the left operand.
- Subtract and Assign Operator (-=): This operator subtracts the right operand from the left operand and then assigns the result to the left operand.
- Multiply and Assign Operator (*=): This operator multiplies the right operand with the left operand and assigns the result to the left operand.
- Divide and Assign Operator (/=): This operator divides the left operand with the right operand and assigns the result to the left operand.
- Modulus and Assign Operator (%=): This operator takes the modulus using two operands and assigns the result to the left operand.
- Left Shift and Assign Operator (<<=): This operator performs a left shift operation on the left operand and assigns the result to the left operand.
- Right Shift and Assign Operator (>>=): This operator performs a right shift operation on the left operand and assigns the result to the left operand.
- Bitwise AND and Assign Operator (&=): This operator performs a bitwise AND operation on the left and right operands and assigns the result to the left operand.
- Bitwise OR and Assign Operator (|=): This operator performs a bitwise OR operation on the left and right operands and assigns the result to the left operand.
- Bitwise XOR and Assign Operator (^=): This operator performs a bitwise XOR operation on the left and right operands and assigns the result to the left operand.
The assignment operator in C returns the value of the variable that was assigned to, which is the value of the expression (a=b) .