Sunday, July 7, 2013

Assignment Operator in C

The assignment operator is used for assigning some value to an operand or a variable. In C, the assignment operator is equal sign (=). In mathematics the significance of the equal to sign is to be sure that both the left and right values of the equal sign have the same value. But in C, its significance is somewhat different.

For example,
x=2+3;
signifies that the expression on the right is evaluated and the resulting value is assigned to the variable on the left side of the equation.



This assignment operator is used to give a value to variable mostly. We can directly assign a value or we can equate to a expression. If we give directly a value, it is stored into the variable. But if we use a expression, then the expression first needs to be resolved. This can be done based on the operator precedence and many conditions come into play while we solve the expression. This will be discussed clearly in the later sections.

Examples:
x=2;
y=(a+(b+3));
z=(x+(y=2));