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), . . .;
Navid Plus is a Tech blog focusing on Science material that I learn day through my College and job. Most likely, blog posts contain C++ Programming, Security, Networking, and Math. Let's have some fun.
Showing posts with label Identifiers. Show all posts
Showing posts with label Identifiers. Show all posts
Wednesday, March 22, 2017
Saturday, March 11, 2017
Intro to C++ Part 7
Identifiers
A C++ identifier must start with either a letter or the underscore symbol, and the remaining characters must all be letters, digits, or the underscore symbol. C++ identifiers are case sensitive and have no limit to their length. There is a special class of identifiers, called keywords or reserved words, which have a predefined meaning in C++ and cannot be used as names for variables or anything else.
The following keywords should not be used for anything other than their predefined purposes in
the C++ language.
| C++ Reserved Keywords |
Subscribe to:
Posts (Atom)
Digital Design Part 3
4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two different implementations of the same instru...
-
The call by reference method of passing arguments to a function copies the reference of an argument into the formal parameter. Inside the...
-
4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two different implementations of the same instru...