Expressions and Assignments

 

Assignment Statement:

Recipient Variable = Expression

 

The equal sign ( = ) is the assignment operator.

It doesn’t mean that the expressions on the left and right are equal – it means that the expression on the right is to be evaluated and that new value used to replace the current value of the variable on the left. I.e., the new value from the expression is assigned to the variable on the left.

 

Expression – a combination of constants, variables, function calls, and operators, which, when evaluated, returns a value.

 

Other Uses of Expressions:

 

Expressions have Boolean properties.

 

The complete assignment statement can, itself, be used as an expression.  

a = b = c;  //Evaluates from right to left.

Once the assignment b = c is evaluated and the assignment is complete, the next assignment, a = b;, is performed.

 

Important Rule:

There can only be a single variable on the left, whereas there can be any expression on the right

 

Summary:

An Assignment Statement assigns the value returned by an expression to a variable.