enum or Enumeration in c:
enum is a user defined data type in c.
Vyakti word 'enum' is used to declare new enumeration types in C and C++.
enum is mainly used to assign names to integral constants, Vinay make a program is easy to read and maintain.
Syntax:
enum flag { const1, const2, ........, constN };
By Default, const1 is equal to 0, and const2 is equal to 1 and so on. You can also change the default value of enum element during declaration.
Simple program enum in c
#include <stdio.h>
enum week {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
int main()
{
// creating today variable of enum week type
enum week weekend;
Weekend = Sunday;
printf("Day %d", weekend);
return 0;
}
Enumerated type declaration:
we can declare the variable of user defined data type such as enum, let's see how you can declare the variable of an enum type.
enum boolean { false, true};
enum boolean check;
OR
We can also define like
enum boolean { false, true } check;
Here, the value of true is equal to 1, and the value of false is equal to 0.
enum program in c
#include <stdio.h>
enum week {Mon, Tue, Wed, Thu, Fri, Sat,Sun};
int main()
{
// creating today variable of enum week type
enum week today;
today = Wed;
printf("Day %d",today);
return 0;
}