Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind C++ Constants?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ myNum = 15; // myNum will always be 153Order
Put the learning moves in the order that makes the concept easiest to apply.
You should always declare the variable as constant when you have values that are unlikely to change:
When you do not want others (or yourself) to change existing variable values, use the const keyword (this will declare the variable as "constant", which means unchangeable and read-only ):
Notes On Constants
Constants
When you do not want others (or yourself) to change existing variable values, use the const keyword (this will declare the variable as "constant", which means unchangeable and read-only ):
const
int myNum = 15; // myNum will always be 15
myNum = 10; // error: assignment of read-only variable 'myNum'You should always declare the variable as constant when you have values that are unlikely to change:
const
int minutesPerHour = 60;Notes On Constants
When you declare a constant variable, it must be assigned with a value:
const int minutesPerHour = 60;