< previous page page_64 next page >

Page 64
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.
Given the declarations
int   num;
int   alpha;
float rate;
char  ch;
we can make the following assignments:
VariableExpression
alpha =2856;
rate =0.36;
ch =B;
num =alpha ;

However, the following assignment is not valid:
ch = Hello;
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:
cout < Hello;
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

 
< previous page page_64 next page >