An enumeration is a type that can hold a set of constant values that are defined by the user. Once you define an enumeration you can use it like integer types.E.g. enum {OFF, ON};The enum defines two integer constants called enumerators and these constants are assigned values by default. The value assigned to OFF = 0 and ON = 1. The above is an unnamed enumeration, however an enum can be named. E.g. enum STATE {OFF, ON};Each enumeration is a distinct type and the type of the enumeration is the enumerator. For example OFF is of type STATE. An enumerator can optionally be initialized by a constant expression of integral type. E.g. enum {WHITE = 3, BLACK = 5}; A value of an integral type can be converter to an enumeration type. This needs to be done explicitly. The results are undefined unless the value is within the range of the enumeration.E.g. enum COLORS {RED = 1; BLUE = 3, WHITE = 7};COLORS c1 = COLORS (5); All enumerators are converted to integral type for any arithmetic operation.
There you go. ^^
Posts 1–7 of 7 · Page 1 of 1
Post a Reply
Tags for this Thread
None
Wouldnt this be the same as DEFINE?
The only difference that I see is that Enumerations increase in number when you dont specify otherwise.
Originally Posted by aanthonyz
Wouldnt this be the same as DEFINE?
The only difference that I see is that Enumerations increase in number when you dont specify otherwise.
nope, you can give them a certain value for ie:
Code:
enum MyEnum{
member1 = 0x45,
member2 = 0xH8
};
And also #define, declares a value which isn't constant. On a enum all the values that are hold are constants and will never change....
Enumeration Allows you to Create your own Data types in which the Data type is constant