Enums

Enums, short for enumerated values, are ways to represent custom variants of a value. For example, computers internally represent a boolean value as a single bit, a 1 or a 0. Therefore, in C, there actually is no bool type, and can be represented as:

From there, you could do something like bool mybool = true;. From the program's point of view, you're basically just using int mybool = 1;. They're called enumerated values because they're internally assigned numbers. Enums only exist so you, the programmer, don't have to use numbers to keep track of states and options.

However, most languages don't automatically make all variables global. An easier to understand example would be an enum in Rust:

You can then use this enum like:

In this way, you could think of i32 (the 32-bit integer type) as an enum of sorts, where every number is a variant.