Thursday, January 5, 2012

What is an assignment statement?

An assignment statement assigns a value to a variable, which means an assignment statement causes a value to be stored in the variable's memory cell. For example, the statement

month = 12;

assigns the integer value 12 to int type variable month. It causes 12, written in 2's complement binary type of notation, to be stored in the month memory cell.

In C, a simple assignment statement takes the form of

variable_name = value;

where this statement assigns the value on the right side of the equal sign to the variable_name on the left side of the equal sign. The binary representation of the value is stored in the variable's memory cell after the assignment has taken placed. The value can be a constant, a variable with a known value, or other, such as a function or an expression that returns a value.

Note that the equal sign in an assignment statement does not really mean equal. As you become exposed to more programming techniques, you will need to interpret an assignment statement by thinking of the table of variable values created and the storing of values in the memory cells rather than the term equal.

No comments:

Post a Comment