`enum` — C Keyword

`enum` — C Keyword

The enum keyword in C: defines a set of named integer constants.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

enum (C)

Defines a set of named integer constants. Enumerators are visible in the enclosing scope.

Syntax

enum Name { ENUMERATOR1, ENUMERATOR2 };
enum Name { A = 1, B = 4, C = 8 };

Example

#include <stdio.h>

enum Color { RED, GREEN, BLUE };
enum Day   { MON = 1, TUE, WED, THU, FRI, SAT, SUN };

const char* color_name(enum Color c) {
    switch (c) {
        case RED:   return "red";
        case GREEN: return "green";
        case BLUE:  return "blue";
        default:    return "unknown";
    }
}

int main(void) {
    enum Color c = GREEN;
    printf("%s\n", color_name(c));   /* green */
    printf("%d\n", WED);             /* 3 */
    return 0;
}

Notes

Example in practice

int main() {
    // Pick one facility from this reference page.
    // Write the smallest program that exercises its main precondition,
    // complexity rule, or lifetime constraint before scaling up.
    return 0;
}