Assignment statements


An assignment statement gives a value to a variable. For example,

x = 5;

gives x the value 5.

The value of a variable may be changed. For example, if x has the value 5, then the assignment statement

x = x + 1;

will give x the value 6.

The general syntax of an assignment statement is

variable = expression;



int i = 0;

price[itemNumber] = 0.80 * price[itemNumber]; = "Fido";


An assignment "statement" is not really a statement (although it is typically used that way), but is an expression. The value of the expression is the value that is assigned to the variable. For example, the expression

i = j = k = 0;

sets all of i, j, and k to zero.