O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

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 Constants

Enumerated constants create a set of constants. For example, you can declare COLOR to be an enumeration; and you can define that there are five values for COLOR: RED, BLUE, GREEN, WHITE, and BLACK.

The syntax for enumerated constants is to write the keyword enum, followed by the type name, an open brace, each of the legal values separated by a comma, and finally a closing brace and a semicolon. Here's an example:

enum COLOR { RED, BLUE, GREEN, WHITE, BLACK };

This statement performs two tasks:

  1. It makes COLOR the name of an enumeration, that is, a new type.

  2. It makes RED a symbolic constant with the value 0, BLUE a symbolic ...

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