Engineering Science 1036A/B Lecture Notes - Lecture 6: Reserved Word, Level Of Measurement
C++ Variables (Objects)
Memory spaces must be reserved to process data/info
Reservations are done using variable/constant names
○
•
Variables: boxes/placeholders in the memory that can hold things
•
Each variable has to be identified by a name, which has to be declared before using it
•
The name of any type of variable/constant/ function/namespace/class is called an
identifier
•
Size of the variable depends on the type of things we are planning to store there
•
We have to tell the compiler in advance (declare):
Names of each of the variables we want
○
The type of things that will be put in each variable
○
•
Identifier Characteristics
An identifier may consist of:
Alphabetical letters
Capital or lowercase
§
○
Numerical Digit (0-9)
○
Special characters: "_" and "$"
○
•
An identifier cannot start with a digit
•
An identifier cannot be a reserved word
•
An identifier can be of any length unless C++ complier has restrictions
Usually are under 31 characters to ensure portability
○
•
Reserved Words
Reserved words (keywords): The words which are reserved for a particular programming
language (grammar)
•
Each keyword has a particular meaning to the programming language
•
Variable Declaration
A variable has to declared by writing the name of the variable as well as the data type it
represents
•
Variables
find more resources at oneclass.com
find more resources at oneclass.com
ing
it
find more resources at oneclass.com
find more resources at oneclass.com
represents
Declaring a variable tells the compiler to allocate enough memory space to hold a value
of this data type and to associate the identifier with this location
•
Re-declaring a variable is a syntax-error in any block statement
•
Built-in Data Types
Mixing different data types
Numerical data types (int,float,double) cannot be mixed with non-numerical data
types (char,string)
•
char
Holds a single character
•
•
toupper() & tolower()
int toupper (int c);
Converts argument "c" to its uppercase equivalent if "c" is a lowercase letter
Otherwise, it returns the same letter
§
anyChracter = toupper (anyChracter);
§
○
•
int tolower (int C);
•
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
Memory spaces must be reserved to process data/info. Variables: boxes/placeholders in the memory that can hold things. Each variable has to be identified by a name, which has to be declared before using it. The name of any type of variable/constant/ function/namespace/class is called an identifier. Size of the variable depends on the type of things we are planning to store there. We have to tell the compiler in advance (declare): Names of each of the variables we want. The type of things that will be put in each variable. An identifier can be of any length unless c++ complier has restrictions. Usually are under 31 characters to ensure portability. Reserved words (keywords): the words which are reserved for a particular programming language (grammar) Each keyword has a particular meaning to the programming language. A variable has to declared by writing the name of the variable as well as the data type it represents ing it represents.