answersLogoWhite

0

What is a enumerated data type?

Updated: 8/11/2023
User Avatar

Wiki User

12y ago

Best Answer

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

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

An enumerated data type is a manufactured data type. The orginal implementation of the boolean data type was an enumerated type.

enum boolean {true, false};

this creates a type : boolean and two constants of type boolean: true and false.

true has an integer value: 0

false as an integer value: 1

The way boolean is now implemented in C and C++ and C# maintains the convention that 0 is true.

A common use of enumerated types is in game programming. You can enumerate the cardinal directions, for example, north, east, south, west, so that you can turn right by performing:

enum compass {north, east, south, west};

compass direction = west;

direction = (direction + 1) % 4

// at this point, direction would be equal to north, or 0

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Enumerated data type is a set of values which are going to be used in the program as constant variables. We can assign any integral value to each member in the set.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a enumerated data type?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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 are categorical variables?

Categorical variables take on a limited and at times a fixed number of value possibilities. If in fields such as Compute Science or Mathematics, they are referred to as enumerated types. In some cases possible values of a variable may be classified as levels.


What is the meaning of the term data domain?

A data domain refers to a specific category or field within a dataset that represents a particular aspect of the data. It helps organize data into logical groupings for easier management and analysis. Examples of data domains include customer information, financial data, and product details.


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

Enumerated


What in enumerated powers?

Enumerated powers


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 data type is age?

integer data type


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.