6. Data types, strings, and vectors Flashcards

1
Q

What is the purpose of the fundamental data types?

A

To store integers, floating-point numbers, and boolean values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Indentify two ways of expressing a floating-point number

A

Using a whole number with decimals, or using scientific notation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between variables and constants?

A

Variables store data that varies as a program runs, wheras constants store data that remains constant as a program runs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which operator is used to assign a value to a variable or constant?

A

The assignment operator ( = ).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe what happens to an expression’s data types when the data types in the expression vary from one another?

A

C++ automatically promotes lower ranking data types to the next higher data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe what happens when you assign a value to a variable that has a lower ranking data type.

A

C++ automatically demotes the value to that data type. This can result in the loss of data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Indentify three functions to convert between numbers and strings

A

stoi(), stod(), and to_sting().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens when an integer variable is assigned a value that’s too big for its type?

A

It will overflow, or wrap around to the type’s minimum.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens when an integer variable is assigned a value that’s too small for its type?

A

It will underflow, or wrap around to the type’s maximum.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is contained within the Standard Template Library (STL) and what are they referred to as?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does a vector contain?

A

A sequence of elements of the same data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which operator is used to access the elements of a vector?

A

The subscript operator ( [ ] ).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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?

A

Out of bounds access occurs. It can lead to unexpected results, and you should always write your code to prevent it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the advantages of using a range-based for loop

A

It automatically iterates over every element in a vector or string without having to specify a counter or use the subscript operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe a string in the context of vectors

A

A sequence of char values, or a string of vector characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe a string in the context of vectors

A

A sequence of char values, or you could also call it a string of vector characters.