Enumerated date type
The enumerated data type gives you an opportunity to invent your own data type and define what values the variable of this data type can take. This can help in making the program listings more readable, which can be an advantage when a program gets complicated. Using enumerated data type can also help you reduce programming errors. It is defined as follows:
enum identifier {value1,value2,......valuen};
The "identifier" is a user-defined enumerated data type which can be used to declare variables that can have one of the values enclosed within the braces (known as enumeration constants). After this definition, we can declare variables to be of this 'new' type as below:
enum day {Monday, Tuesday,.... Sunday };
enum day week_st, week_end;
week_St = Monday;
week_end=Friday;
If (week_st==Tuesday)
week_end=Saturday;
The compiler automatically assigns integer digits beginning with 0 to all the enumeration constants. That is, enumeration constant Monday is assigned 0, Tuesday is assigned 1, and so on. However the automatic assignments can be overridden by assigning values explicitly to the enumeration constants. For Example:
enum day {Monday =1,Tuesday,.........Sunday};
Here, the constant Monday is assigned the value of 1. The remaining constants are assigned values that increase by one. The definition and declaration of enumerated variables can be combined in one statement. Example:
enum day {Monday,.... Sunday} week_st, week_end;