# Assignment Operators in C

Assignment operator (=) is used to store or copy values into memory location. Copying or storing into memory location is called assigning hence the name is assignment operator.

Syntax : variable = expression; // expression can be a constant/variable/expression

For example :

x = y; //Store the value of y into x*/

x = 4 + 5; //Compute the addition of 4 and 5, .i.e 9 and store it into variable x

pi = 3.1416; // Store 3.1416 into variable pi

There are many shorthand notations for assignment operators. Like a+=1, it is equivalent to a = a + 1; Below table shows short hand assignment operator and their description.

Operator |
Example |
Meaning |
Description |

+= |
a += 2 |
a = a + 2 |
Perform a+2 and store result in a |

-= |
a -= 2 |
a = a - 2 |
Perform a-2 and store result in a |

*= |
a *= 2 |
a = a * 2 |
Perform a*2 and store result in a |

/= |
a /= 2 |
a = a / 2 |
Perform a/2 and store result in a |

%= |
a %= 2 |
a = a % 2 |
Perform a%2 and store result in a |

<<= |
a <<= 2 |
a = a << 2 |
Perform a<<2 and store result in a |

>>= |
a >>= 2 |
a = a >> 2 |
Perform a>>2 and store result in a |

&= |
a &= 2 |
a = a & 2 |
Perform a&2 and store result in a |

^= |
a ^= 2 |
a = a ^ 2 |
Perform a^2 and store result in a |

|= |
a |= 2 |
a = a | 2 |
Perform a|2 and store result in a |