Wednesday, March 22, 2017

C++ Part 38

Review Part I
Identifiers
Identifiers are used as names for variables and other items in a C++
program. An identifier must start with either a letter or the underscore
symbol, and the remaining characters must all be letters, digits, or the
underscore symbol.

Variable Declarations
All variables must be declared before they are used. The syntax for variable
declarations is as follows:
SYNTAX Type_Name Variable_Name_1, Variable_Name_2, . . .;
EXAMPLES:
int count, number_of_dragons, number_of_trolls;
double distance;

Syntax
The syntax for a programming language (or any other kind of language) is
the set of grammar rules for that language. For example, when we talk
about the syntax for a variable declaration (as in the box labeled “Variable
Declarations”), we are talking about the rules for writing down a well-formed
variable declaration. If you follow all the syntax rules for C++, then
the compiler will accept your program. Of course, this only guarantees that
what you write is legal. It guarantees that your program will do something,
but it does not guarantee that your program will do what you want it to do.

Assignment Statements
In an assignment statement, first the expression on the right-hand side of
the equal sign is evaluated, and then the variable on the left-hand side of
the equal sign is set equal to this value.
SYNTAX Variable = Expression;
EXAMPLES distance = rate * time;
count = count + 2;

Initializing Variables in Declarations
You can initialize a variable (that is, give it a value) at the time that you
declare the variable.
SYNTAX
Type_Name Variable_Name_1 = Expression_ for_Value_1,
Variable_Name_2 = Expresssion_ for_Value_2, . . .;
EXAMPLES
int count = 0, limit = 10, fudge_factor = 2;
double distance = 999.99;
Alternative Syntax for Initializing in Declarations
Type_Name Variable_Name_1 (Expression_ for_Value_1),
Variable_Name_2 (Expression_ for_Value_2), . . .;



No comments:

Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two diļ¬€erent implementations of the same instru...