C Enumeration

1. What is a C Enumeration?
A C Enumeration (
enum) is a user-defined data type in C.It consists of a set of named integer constants.
Makes code more readable and less error-prone compared to using raw integers.
Syntax:
2. Example: Basic Enum
Output:
By default, the first enumerator has value
0, the next1, and so on.
3. Assigning Custom Values
Output:
After
Sunday = 1, the next members automatically increment (Monday = 2,Tuesday = 3, …).
4. Using Enum with Switch Case
Output:
5. Enum with Typedef
Output:
typedefallows you to useColordirectly without writingenum Color.
6. Key Points About Enumerations
Enum members are constants of type
intby default.Useful for readable code instead of using raw integers.
Default values start from
0and increment by1.You can assign custom integer values.
Can be used with switch statements for better clarity.
Combine with
typedeffor simpler syntax.
