6. Data types, strings, and vectors Flashcards
What is the purpose of the fundamental data types?
To store integers, floating-point numbers, and boolean values.
Indentify two ways of expressing a floating-point number
Using a whole number with decimals, or using scientific notation.
What is the difference between variables and constants?
Variables store data that varies as a program runs, wheras constants store data that remains constant as a program runs.
Which operator is used to assign a value to a variable or constant?
The assignment operator ( = ).
Describe what happens to an expression’s data types when the data types in the expression vary from one another?
C++ automatically promotes lower ranking data types to the next higher data type.
Describe what happens when you assign a value to a variable that has a lower ranking data type.
C++ automatically demotes the value to that data type. This can result in the loss of data.
Indentify three functions to convert between numbers and strings
stoi()
, stod()
, and to_sting()
.
What happens when an integer variable is assigned a value that’s too big for its type?
It will overflow, or wrap around to the type’s minimum.
What happens when an integer variable is assigned a value that’s too small for its type?
It will underflow, or wrap around to the type’s maximum.
What is contained within the Standard Template Library (STL) and what are they referred to as?
The STL contains many data types in addition to the fundamental types.
The STL types that contain collections of other data types are often called containers.
What does a vector contain?
A sequence of elements of the same data type.
Which operator is used to access the elements of a vector?
The subscript operator ( [ ] ).
What happens if your code specifies an index that’s outside the range of valid indexes, what can happen, and what should you do to prevent this from happening?
Out of bounds access occurs. It can lead to unexpected results, and you should always write your code to prevent it.
What are the advantages of using a range-based for loop
It automatically iterates over every element in a vector or string without having to specify a counter or use the subscript operator.
Describe a string in the context of vectors
A sequence of char values, or a string of vector characters.