Programming Logics FORUMS

Full Version: enum in C++
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
enum

Syntax:
Code:
enum name {name-list} var-list;

Details:

The enum keyword is used to create an enumerated type named name that consists of the elements in name-list. The var-list argument is optional, and can be used to create instances of the type along with the declaration. For example, the following code creates an enumerated type for colors:
Code:
enum ColorT {red, orange, yellow, green, blue, indigo, violet};
     ...
     ColorT c1 = indigo;
     if( c1 == indigo ) {
       cout << "c1 is indigo" << endl;
     }
In the above example, the effect of the enumeration is to introduce several new constants named red, orange, yellow, etc. By default, these constants are assigned consecutive integer values starting at zero. You can change the values of those constants, as shown by the next example:
Code:
enum ColorT { red = 10, blue = 15, green };
     ...
     ColorT c = green;
     cout << "c is " << c << endl;
When executed, the above code will display the following output:
Code:
c is 16
Hi Everyone..

I have recently join this site and this is nice idea for providing us information about enum. Would you mind to let us know more about this? Thanks!
Reference URL's