Enumerations
In this lesson, we look at how to restrict a variable to a finite number of distinct values.
We'll cover the following...
What is an enumeration?
Some computations can involve a variable whose value can be one of a seemingly endless array of possibilities. In other cases, a variable’s value can have only certain values. For example, a Boolean variable must be true or false. To represent a letter grade A, B, C, D, or F, we could use a char
variable—grade
, for example—but restrict its value to only those five letters. In reality, however, grade
could
contain any character, not just the letters A, B, C, D, and F. To prevent this, instead of declaring grade
as a char
, we can declare it as an ...
Access this course and 1400+ top-rated courses and projects.