Enumeration in c

Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.

The keyword ‘enum’ is used to declare new enumeration types in C and C++. Following is an example of enum declaration.

// An example program to demonstrate working 
// of enum in C 
#include<stdio.h> 
enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun}; 
int main() 
{ 

    enum week day; 

    day = Wed; 

    printf("%d",day); 

    return 0; 
}  

Output -

2

In the above example, we declared “day” as the variable and the value of “Wed” is allocated to day, which is 2. So as a result, 2 is printed.

Posted on by