Enum
giving meaningful names to not-meaningful numbers
Enumeration
Enumeration (aka Enum): User-defined data type for assigning names to constants, so the code becomes more legible.
We will use
UPPER_SNAKE_CASEmost of the time for enums.
enum week {
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
};
/**
* SUNDAY corresponds to 0
* MONDAY corresponds to 1
* ...
* SATURDAY corresponds to 6
* /Sample Code
Output:
You can also declare enum variables.
Sample Code
Output:
Enums are useful when we want to define multiple variables which can be grouped together.
Last updated