RAD Studio |  |

Enumeration Constants
See Also
Collapse All

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,

Copy Code

    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

Copy Code

    giants = 0, cubs = 1, dodgers = 2

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

Copy Code

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

the constants are set as follows:

Copy Code

    giants = 0, cubs = 3, dodgers = 1

The constant values need not be unique:

Copy Code

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

See Also

Constants

Integer Constants

Integer Constant Without L Or U

Floating Point Constants

Character Constants

The Three Char Types

Escape Sequences

Wide-character And Multi-character Constants

String Constants

Constants And Internal Representation

Internal Representation Of Numerical Types

Constant Expressions

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!