Enumeration (enums)
Enum is short for “Enumeration”. It allows the user to create custom data types with a set of named integer constants. The “enum” keyword is used to declare an enumeration. Enum simplifies and makes the program more readable.
Syntax
enum enum_name {const1, const2, ..., constN};
Here, the const1 will be assigned 0, const2 = 1, and so on in the sequence.
We can also assign a custom integer value such as:
enum enum_name { const1 = 8; const2 = 4; }
Example
C
// C code to implement enum #include <stdio.h> // Declaring a enum enum Cafes { Dyu_Art_Cafe, Tea_Villa_Cafe, The_Hole_in_the_Wall_Cafe, Cafe_Azzure, The_Banaglore_Cafe, Dialogues_Cafe, Cafe_Coffee_Day }; // driver code int main() { enum Cafes today = The_Banaglore_Cafe; printf ( "Today is %d\n" , today); return 0; } |
Today is 4
User-Defined Data Types In C
Data Types are the types of data that can be stored in memory using a programming language. Basically, data types are used to indicate the type of data that a variable can store. These data types require different amounts of memory and there are particular operations that can be performed on them. These data types can be broadly classified into three types:
- Primitive Data Types
- Derived Types
- User Defined Data Types
In this article, will discuss the User-Defined Data Type.