enum PreciousMetal {
Platinum, Gold, Silver
};
//значения можно задать явно, следующие продолжаются от них
enum Planet {
Mercury = 1, Venus, Earth
};
//typedef избавляет от слова enum; C23 умеет фиксировать нижележащий тип
typedef enum : unsigned char {
Summer, Fall, Winter, Spring
} Season;
enum PreciousMetal gold = Gold;
//gold is 1
enum Planet earth = Earth;
//earth is 3
Season fall = Fall;
//fall is 1
size_t seasonSize = sizeof fall;
//seasonSize is 1
//значение перечисления - число: имя берётся из массива строк
const char *seasonNames[] = {"Summer", "Fall", "Winter", "Spring"};
//seasonNames[fall] is "Fall"
printf("gold is %d\n", gold);
printf("earth is %d\n", earth);
printf("fall is %d\n", fall);
printf("seasonSize is %zu\n", seasonSize);
printf("seasonNames[fall] is %s\n", seasonNames[fall]);