Enumerations
An enumeration is a user defined data type whose values consist of a set of named integer constants, and are used for the sole purpose of making program code more readable.
Syntax: enum tag { value_list } [ enum_var ] ;
where tag is the name of the enumeration type, value_list is a list of valid values for the enumeration, and where enum_var is an actual variable of this type.
For Example :-
enum colours { red, green, blue, orange } shade ;
// values red – 0, green – 1, blue – 2, orange – 3
enum day { sun = 1, mon, tue, wed = 21, thur, fri, sat } ;
enum day weekday ;
// values are 1, 2, 3, 21, 22, 23, 24
Variables declared as enumerated types are treated exactly as normal variables in use and are converted to integers in any expressions in which they are used.
For Example :-
int i ;
shade = red ; // assign a value to shade enum variable
i = shade ; // assign value of enum to an int
shade = 3 ; // assign valid int to an enum, treat with care