# Assignment operators.

C has the following assignement operators:

    	=   +=   -=   *=   /=   %=   <<=   >>=   &=   ^=   |=

= is the obvious one. It takes the result of the expression on the right and assigns it to the variable on the left (lvalue).

    	main ()
            {
    	  int a, b=4, c=10;
    	  a = b + c;
    	}

I know this is stating the obvious, but:

1. b is assigned the value 4
2. c is assigned the value 10
3. a is assigned the result of b plus C (14).

All the other operators act in a simular way. If you find yourself coding the example on the left, it could be changed to the example on the right.

    	main ()				main()
    	{				{
    	  int a=4;			  int a=4;
    	  a = a * 4;			  a *= 4;
    	}				}

The rule is as follows:

The lvalue is multiplied by the rvalue and the result assigned to the lvalue.

Here is another example.

    	main()				main()
    	{				{
    	    int a=10, b=2;	            int a=10, b=2;
    	    a /= b * 5;		            a = a / (b*5);
    	}				}

Again both preduce the same answer (1).

Increment (++) and Decrement (--)
Bit shifting ( >>= <<= )
Operator precedence table.

Top | Master Index | Keywords | Functions