answersLogoWhite

0

An enumeration is a group of (closely) related constants of integral type (int, char, short, long or long long).

Members of an enumeration are automatically initialised with values in the order they are declared, starting with the value 0 for the first member and incrementing by 1 for each additional member:

enum traffic_light {green, amber, red}; // e.g., green=0, amber=1, red=2

If the start value 0 is undesirable, we can assign a different start value:

enum traffic_light {green=1, amber, red}; // e.g., green=1, amber=2, red=3

A new start value can be placed anywhere in an enum:

enum traffic_light {green, amber=4, red}; // e.g., green=0, amber=4, red=5

Two or more members can share the same value:

enum traffic_light {green, amber, orange=1, red}; // e.g., green=0, amber=1, orange=1, red=2

The value of a previously declared member can be used to initialise another member:

enum traffic_light {green, amber=green+1, red=green+2}; // e.g., green=0, amber=1, red=2

The names of an enumeration are within the scope of the declaration. This is often undesirable as two enumerations in the same scope cannot share the same member names:

enum traffic_light {green, amber, red};

enum rainbow {red, orange, yellow, green, blue, indigo, violet}; // error!

To avoid this, we can use an enum class. The enumeration then becomes a namespace:

enum class traffic_light {green, amber, red};

enum class rainbow {red, orange, yellow, green, blue, indigo, violet}; // ok

To refer to a member of an enum class, we use namespace resolution:

traffic_light x = red; // error! no red in scope

rainbow y = rainbow::green; // ok

User Avatar

Wiki User

7y ago

What else can I help you with?

Related Questions

Do the elements of an enumerated data type have to be specified explicitly?

yes.


What does the term enum refer to in computer programming?

The term 'enum' is short for 'enumerated type'. An enumerated type is a data type containing a set of values called elements. They can also be called members or enumerators.


An enumerated data type is another user defined type which provide a way for attaching names to numbers thereby increase clearity of the code?

Yes. Enumerated types are constant values that are grouped under a common type.


Which type of power is exercised when Congress makes changes to the bankruptcy laws?

enumerated power


Which type of power is exercise when Congress declares war on another country?

enumerated power


What in enumerated powers?

Enumerated powers


What type of power id it that permits congress to declare war on a foreign nation?

Enumerated


What is the meaning of the term data domain?

In data management and database analysis, a data domain refers to all the unique values which a data element may contain. The rule for determining the data boundary may be as simple as a data type with an enumerated list of values.


What are enumerated data types in pascal?

Pascal has 4 primitive data types: integer; boolean; char and; real. These 4 provide the basic building blocks for more complex types.


What did it mean if an item was on the enumerated list?

"Enumerated" means numbered. An enumerated list means a list which is ordered by numbering.


What data type is age?

integer data type


What is data and define its type?

Data is information. Data type defines the type of data - integer, character etc