3- variables, identifiers, assignment, input/output Flashcards
Variable
a named memory location
Variable value
data stored in variable
variable always has a value
Identifiers
name of a variable or any other named construct
Identifier naming conventions
identifier must start with a letter or underscore symbol (_), the rest of the characters should be letters, digits or underscores
Snake Case
terse, use abbreviations and underscores to separate the words, never use capital letters for variables
min
temperature
camera_angle
cur_point_nmbr
Camel Case
if multiple words: capitalize, do not use underscores
variant: first letter lowercased
1:
Min
Temperature
CameraAngle
CurrentNumberPoints
2:
min
temperature
cameraAngle
currentNumberPoints
Keywords
identifiers reserved as part of the language
int, return, float, double
cannot be used by the programmer to name constructs
consist of lowercase letters only
have special meaning to the compiler
Declaration
introduction of the name to the compiler
before use, every variable in C++ program needs to be declared
example declarations:
int numberOfBars;
double weight, totalWeight;
Type
the kind of data stored in a variable
Assignment statement
an order to the computer to set the value of the variable on the left-hand side of equal sign to the value of the right-hand side
example:
numberOfBars = 37;
totalWeight = oneWeight;
totalWeight = oneWeight * numberOfBars;
numberOfBars = numberOfBars + 3;
Stream
a sequence of data to be processed
Input stream
data to be input into program
Output stream
data generated by the program to be output
«
is insertion operator, it inserts data into the output stream
> >
extraction operator