Enumerations (enum) in C Programming (Complete Guide with Examples)
This tutorial explains enumerations (enum) in C, which allow defining a set of named integer constants. It covers declaration, usage, and practical examples, helping beginners write more readable and maintainable code.
1. What is an Enumeration
- An enumeration is a user-defined data type that assigns names to integer constants.
- Helps make code readable and maintainable.
2. Syntax
- By default, the first constant is
0, second is1, and so on. - You can assign custom values.
3. Example: Basic Enumeration
Sample Output:
4. Example: Enumeration with Custom Values
Sample Output:
5. Key Points to Remember
enumcreates named integer constants- Improves code readability instead of using raw numbers
- Default values start from 0 but can be customized
- Can be used with variables, arrays, and switch statements
- Often combined with structures and unions for organized data representation