Thuta Learning
AdvancedProgrammingbeginner

Enums

Relax. We'll talk through this in plain words — no textbook voice.

enum is a type that groups related constants under readable names. Writing status codes, levels, menu choices, or directions as an enum instead of bare numbers makes your code much easier to read.

c
#include <stdio.h>

enum Level {
  LOW,
  MEDIUM,
  HIGH
};

int main() {
  enum Level current = MEDIUM;

  if (current == MEDIUM) {
    printf("Current level is medium.");
  }
  return 0;
}

LOW, MEDIUM, and HIGH default to 0, 1, and 2 — but the names carry a lot more meaning for anyone reading the code than the raw numbers would.

You should see
Current level is medium.

Info

Give your enum names real business meaning. For example, ORDER_PENDING, ORDER_PAID, ORDER_CANCELLED.

Easy traps

  • Since enum values are really just integer constants under the hood, type safety can be weaker than you'd expect — double-check your value logic.
Enums | Thuta Learning