C assignment operators
Created By: chatGPT
C assignment operators are used to assign values to variables. The simplest assignment operator is the equal sign (
=
). There are also several compound assignment operators that combine an arithmetic operation with an assignment. Here’s a brief overview of these operators:1. Simple assignment operator: This operator assigns the value on the right to the variable on the left.
int a = 10;
2. Addition assignment operator (
+=
): This operator adds the right operand to the left operand and assigns the result to the left operand.a += 5; // a is now 15
3. Subtraction assignment operator (
-=
): This operator subtracts the right operand from the left operand and assigns the result to the left operand.a -= 3; // a is now 12
4. Multiplication assignment operator (
*=
): This operator multiplies the left operand by the right operand and assigns the result to the left operand.a *= 2; // a is now 24
5. Division assignment operator (
/=
): This operator divides the left operand by the right operand and assigns the result to the left operand.a /= 4; // a is now 6
6. Modulus assignment operator (
%=
): This operator takes the modulus using the two operands and assigns the result to the left operand.a %= 5; // a is now 1