Assignment Operators

                     These are used to assign a constant value or values of the expression to an identifier.

                     These are two types,

1. Simple Assignment ( = ):

                    Simple Assignment Operator is used to assign values from left side operand to the right side operand.
                    Eg: C = A+B will assign the values of A+B to C

2. Shorthand (or) Compound Assignment:


* Addition and Assignment Operator( += )

                    Addition and Assignment operator is used to Addition of right operand to the left operand and assign the result to the left operand.

                    Eg:  C+=A   i.e.  C=C+A


* Subtraction and Assignment Operator( -= )

                    Subtraction and Assignment operator is used to Subtraction of right operand from the left operand and assign the result to the left operand.

                    Eg:  C-=A   i.e.  C=C-A


* Multiplication and Assignment Operator( *= )

                    Multiplication and Assignment operator is used to Multiplication of left operand with the right operand and assign the result to the left operand.

                    Eg:  C*=A   i.e.  C=C*A


* Division and Assignment Operator( /= )

                    Division and Assignment operator is used to Divide of left operand with the right operand and assign the result to the left operand.

                    Eg:  C/=A   i.e.  C=C/A


* Modulus and Assignment Operator( %= )

                    Modulus and Assignment operator is used to Take Modulus between the two operands and assign the result to the left operand.

                    Eg:  C%=A   i.e.  C=C%A


* Left Shift and Assignment Operator( <<= )

                    Left Shift and Assignment Operator is used Take the value in Binary form and left shifted by 2 bits and stored in left operand.
                    Eg:  A=4, B
                            A=4 ---> 1 0 0 (Binary form)
                            B =A<<2; 1 0 0 0 0 (Binary Form)
                             By calculating the above binary number we can get 24 =16
                            Final B= 16


* Right Shift and Assignment Operator( >>= )

                    Right Shift and Assignment Operator is used Take the value in Binary form and right shifted by 2 bits and stored in left operand.
                    Eg:  A=4, B
                            A=4 ---> 1 0 0 (Binary form)
                            B =A>>2; 1 0  (Binary Form)
                             By calculating the above binary number we can get 21 =2
                            Final B= 2



Next Topic        :  Increment and Decrement Operator

Previous Topic :  Logical Operators

No comments:

Post a Comment