Defining Enums
Create readable named values.
What Is an Enum?
An enumeration (enum) is a user-defined type that groups a set of named integer constants.
Instead of remembering that 0 means Monday and 1 means Tuesday, you give those numbers readable names. This makes code clearer and harder to get wrong.
Basic Syntax
You declare an enum with the enum keyword, a tag name, and a list of names in braces.
Each name becomes a constant you can use anywhere an integer is expected.
enum Weekday { MON, TUE, WED, THU, FRI };All lessons in this course
- Defining Enums
- Enum Values and Ranges
- const Variables
- #define Constants