C++ Enum (Enumeration) is a user-defined datatype where we specify the set of values for a variable, and the variable can only take one out of a small set of possible values.

C++ Enum Example

An enumeration is the distinct type whose value is restricted to the range of values (see below for details), which may include a several explicitly named constants (“enumerators“). The values of the constants are the values of an integral type known as an underlying type of the enumeration.

Keyword and Syntax

If we want to declare an enumeration, we use the keyword enum.

The syntax is the following.

enum enum_name {const1, const2, const3,..., const-n};

Example:

enum months {Jan, Feb, March, April, May};

Here, enum name is month and Jan, Feb, March… are the type of months.

#c++ #enum #c++ enum

C++ Enum Example | Enumeration (or enum) in C++
6.65 GEEK