O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enumerated Types

You can use the enumerated type to declare symbolic names to represent integer constants. By using the enum keyword, you can create a new “type” and specify the values it may have. (Actually, enum constants are type int, therefore they can be used wherever you would use an int.) The purpose of enumerated types is to enhance the readability of a program. The syntax is similar to that used for structures. For example, you can make these declarations:

enum spectrum {red, orange, yellow, green, blue, violet} ;
enum spectrum color;

The first declaration establishes spectrum as a tag name, which allows you to use enum spectrum as a type name. The second declaration makes color a variable of that type. The identifiers within the braces ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required