enumerated data type

a user defined Data type, which is used to store the values (char type values) which is already fixed in real world. Values ​​are fixed as if a 7 days or one year is 12 months, which never changes.

This type of data type is used only for fixed value which we already know, in which values ​​can be stored only by initializing in the Parenthesis bracket i.e. in the program by entering the user from outside Can not be stored.

Syntex to initialize this is given below-

SYNTEX:-

enum tag-name {enumeration list};

Where the tag-name is an identifier.
Example:-

enum weak = {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}day;

In enum data type, there are also a number of attache with store values in which the default number 0 starts with (which you can also change) which is forward increment. like-

Sunday=0, Monday=1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5, Saturday=6

These values can be accessed by both their numbers and names.
Example:-

#include<iostream.h>
#include<conio.h>

void main()
{
 clrscr();
 enum weak{Sunday,Monday,tuesday,Wednesday,Thursday,Friday,Saturday}day;
 int d; 
 
  cout<<"Enter name: ";
 cin>>d;
 day=d;
 
 switch(day)
{
 case 0: cout<<"Sunday"; break;
 case 1: cout<<"Monday"; break;
 case 2: cout<<"Tuesday"; break;
 case 3: cout<<"Wednesday"; break;
 case 4: cout<<"Thursday"; break;
 case 5: cout<<"Friday"; break;
 case 6: cout<<"Saturday"; break;
 default: cout<<"Week have only 7 days"; break;
 }
getch();
}
OUTPUT:-
Enter name: 1
Monday

In the enumeration list, if a number is assigned to a value, then the value in it will be assigned serial number like the increment number.

enum weak={Sun=1, Mon, Tue, Wed, Thu=1, Fri, Sat}day;

Here is the example,

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

 enum weak
 {
  Sun=1,Mon,tue,Wed,
  Thur=1,Fri,Sat
 };

cout<<Sun<<" "<<Mon<<" "<<tue<<" "<<Wed<<" "<<Thur<<" "<<Fri<<" "<<Sat;
getch();
}
OUTPUT:-
1 2 3 4 1 2 3

previous-modifier and their type

next-typedef Data-Type in C++