Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
An enum is a user-defined type consisting of a set of named integer constants. It makes code more readable and self-documenting.
enum Color { RED, GREEN, BLUE };
Color myColor = GREEN;
if (myColor == GREEN) {
// RED is 0, GREEN is 1, BLUE is 2
}enum class Status { PENDING, SUCCESS, FAILED };
Status s = Status::SUCCESS; // Scoped & Type-safe!Always prefer enum class to prevent naming collisions and accidental integer conversions.
You can assign specific values to enum members. By default, they start at 0 and increment by 1.
enum HTTP { OK = 200, ERROR = 404, TIMEOUT = 408 };