|
|
|
|
|
|
|
the expression (what is on the right-hand side of the assignment operator) is evaluated, and that value is stored into the single variable on the left of the assignment operator. A variable keeps its assigned value until another statement stores a new value into it. |
|
|
|
|
|
|
|
|
int num;
int alpha;
float rate;
char ch; |
|
|
|
|
|
|
|
|
we can make the following assignments: |
|
|
|
|
| Variable | Expression | | alpha = | 2856; | | rate = | 0.36; | | ch = | B; | | num = | alpha ; |
|
|
|
|
|
|
However, the following assignment is not valid: |
|
|
|
|
|
|
|
|
A char variable can hold only one character. For the time being, the only thing we do with strings is print them out as messages: |
|
|
|
|
|
|
|
|
Expressions are made up of constants, variables, and operators. The following are all valid expressions: |
|
|
|
|
|
|
|
|
alpha + 2 rate - 6.0 4 - alpha rate alpha * num |
|
|
|
|
|
|
|
|
The operators allowed in an expression depend on the data types of the constants and variables in the expression. The arithmetic operators are |
|
|
|
|
|