Skip to content

C Enums

Enums (enumerations) are user-defined types that consist of named integer constants.

1. Basic Enum

c
enum Color {
    RED,
    GREEN,
    BLUE
};

2. Enum with Values

c
enum Weekday {
    MONDAY = 1,
    TUESDAY = 2,
    WEDNESDAY = 3,
    THURSDAY = 4,
    FRIDAY = 5
};

3. Using Enums

c
enum Color favorite_color = BLUE;
if (favorite_color == RED) {
    printf("Your favorite color is red\n");
}

4. Enum Size

c
printf("Size of enum: %zu\n", sizeof(enum Color));

Content is for learning and research only.