Assignment Operators

Assignment operators are used to assign the values present on right side to the operand present on the left side of the operators. Following are the various assignment operators available in C Language.

i. = operator

This operator assign the value present on the right side of the operator to the operand present on the left side of the operator. Example:

Consider A = 10, B = 20 and C = 5
C = A + B  would results C = 30

ii. += operator

This operator will first add the operands present on either side of the operator and then assign the resultant value on the operand present on left side. Example:

Consider A = 10, B = 20 and C = 5
B += C  is equivalent to B = B + C and would results B = 25

iii. -= operator

This operator will first subtract the right operand from left operand and then assign the resultant value on the operand present on left side. Example:

Consider A = 10, B = 20 and C = 5
B -= C  is equivalent to B = B - C and would results B = 15

iii. *= operator

This operator will first multiply both the operands present on either side and then assign the resultant value on the operand present on left side. Example:

Consider A = 10, B = 20 and C = 5
B *= C  is equivalent to B = B * C and would results A = 100

iiv. /= operator

This operator will first divide left operand by right operand and then assign the resultant value on the operand present on left side. Example:

Consider A = 10, B = 20 and C = 5
B /= C  is equivalent to B = B / C and would results B = 4

Program example of assignment operators

//An example of assignment operators
#include<stdio.h>

int main()
{
    int A=10, B=20, C=5;
  
    printf("Consider A = 10 and B = 20 and C=5 \n");

    C = A + B;
    printf(" = operator (C = A + B) = %d \n",C);

    A=10, B=20, C=5;
    printf(" += operator (B+=C) = %d \n",B+=C);

    A=10, B=20, C=5;
    printf(" -= operator (B-=C) = %d \n",B-=C);

    A=10, B=20, C=5;
    printf(" *= operator (B*=C) = %d \n",B*=C);

    A=10, B=20, C=5;
    printf(" /= operator (B/=C) = %d \n",B/=C);

  return 0;
}

Output

Consider A = 10 and B = 20 and C=5
 = operator (C = A + B) = 30
 += operator (B+=C) = 25
 -= operator (B-=C) = 15
 *= operator (B*=C) = 100
 /= operator (B/=C) = 4