Enumeration Constants

From RAD Studio
Jump to: navigation, search

Go Up to Constants Overview Index

Enumeration constants are identifiers defined in enum type declarations. The identifiers are usually chosen as mnemonics to assist legibility. Enumeration constants are integer data types. They can be used in any expression where integer constants are valid. The identifiers used must be unique within the scope of the enum declaration. Negative initializers are allowed. See Enumerations and enum (keyword) for a detailed look at enum declarations.

The values acquired by enumeration constants depend on the format of the enumeration declaration and the presence of optional initializers. In this example,

enum team { giants, cubs, dodgers };

giants, cubs, and dodgers are enumeration constants of type team that can be assigned to any variables of type team or to any other variable of integer type. The values acquired by the enumeration constants are

giants = 0, cubs = 1, dodgers = 2

in the absence of explicit initializers. In the following example,

enum team { giants, cubs=3, dodgers = giants + 1 };

the constants are set as follows:

giants = 0, cubs = 3, dodgers = 1

The constant values need not be unique:

enum team { giants, cubs = 1, dodgers = cubs - 1 };

See Also