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.