Identifiers Flashcards
In C++ there are 6 basic containers
(int, float, double,
char, string, and boolean)
int (Integer)
used to store whole numbers, positive
and negative, including zero
float and double
used to store decimal numbers, positive
and negative.
char (character)
used to store a “single” letter, number,
symbol, or space. [All char types use ‘’]
string
used to store “zero or more” letters, numbers,
symbols, or spaces. [All string types use “”]
bool (boolean)
used to hold boolean logic, which can contain
a value of 0 or 1.
Declaring (creating) variables and constants (Three steps)
a) Choose the data type (or container)
b) Choose the indentifier name (label it)
c) Initialize the value (Required for constants)
c) Initialize the value (Required for constants
- numerical values - initialize with a 0
2. non-numerical values - initialize with a empty string or char
ex identifiers
int age = 0; string bldgName = " "; char middle_Initial = ' '; bool isActive = 0; float gpa = 0; const double PI = 3.14; const int DAYS_OF_THE_WEEK = 7;
Naming convention for indentifiers
a) If it is defined as a const type, use ALL-CAPS for the name
b) For multi-word names, either use camel-case or underscores
c) Always start with a letter
d) After the first letter of the name, you can use letters,
numbers, and underscores.
Assigning values to variables
a) The assignment operator “=” is used to assign values
b) The right-hand side is assigned to the left (LHS = RHS)
Other notes
a) You can’t use a variable unless you DECLARE IT FIRST.
b) When you give a variable or constant a name, it is bound
by that EXACT name. (C++ is CaSe SeNsItIvE)
ex. int age = 0; AND int aGe = 0; (Different variables)
[Ex.] Declare identifiers
Re-assign variables
int age = 0; string bldgName = " "; char middle_Initial = ' '; bool isActive = 0; float gpa = 0; const double PI = 3.14; const int DAYS_OF_THE_WEEK = 7;
int num1 = 10000; int num2 = 20; string name = "William"; char grade = 'A'; bool isGraduating = 1; float gpa = 3.2;