Home Segments Index Top Previous Next

431: Mainline

Although there is nothing wrong with defining macros, many experienced C programmers would be more likely to use an enumeration declaration, as in the following example:

enum {food, trucking, computers, metals, health, airline}; 

Such a declaration identifies all the symbols in braces as enumeration constants, and assigns integer values to those constants. By default, the value of the first enumeration constant is 0; also by default, the value of each succeeding enumeration constant is 1 more than the previous value. Hence, the value of food is 0 and the value of trucking is 1.