CodesandTutorials
Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.
You are here - Home > Programming > C > Basics

Assignment Operators


Description

The most common assignment operator is equal represented by symbol '=', which assigns or changes the value of left operand to its right operand or expression.

a = a + b;     // adds value of a & b to a

In the above statement 'a' variable is repeated twice, to eliminate such common variables C language offers shorthand way to represent such statements by combining arithmetic operator and assignment operator. Below is the statement that exactly has same effect as one shown above.

a += b;     // adds value of a & b to a

Similarly other assignment operators are

  • -= substraction and assignment
  • *= multiplication and assignment
  • /= division and assignment
  • %= mudulo division and assignment
  • <<= left shift and assignment
  • >>= right shift and assignment
  • &= bitwise AND and assignment
  • ^= bitwise OR and assignment
  • |= bitwise XOR and assignment.

Tip Box

Operator precedence

Priority Operator
1st *=
2nd /=
3rd %=
4th +=
5th -=
6th &=
7th ^=
8th |=
9th <<=
10th >>=

Advertisement





Terms of Use | Privacy Policy | Contact Us | Advertise
CodesandTutorials © 2014 All Rights Reserved