C - Data Type Enumerator Values

Introduction

You can specify your own integer value for any or all of the enumerators explicitly.

The following code defines the Weekday type so that the enumerator values start from 1:

enum Weekday {Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};

The enumerators that follow an enumerator with an explicit value will be assigned successive integer values.

This can cause enumerators to have duplicate values.

Here's another example of defining an enumeration:

enum Suit{clubs = 10, diamonds, hearts, spades};
enum Suit card_suit = diamonds;
enum FaceValue { two=2, three, four, five, six, seven,
                 eight, nine, ten, jack, queen, king, ace};

Related Topic