Enum
Enum
It gives you an opportunity to invent your own data type and define what
values the variable of this datatype can take.
The format of the enum definition is similar to that of a structure.
Example:
Enum mar_status{Single,married,divorced,widowed;
};
Enum mar_status person1,person2;
The first part declares the data type and specifies it’s possible values.
These values are called “enumerators”
#include<stdio.h>
#include<conio.h>#include<string.h>
void main()
{
enum emp_dept
{
assembly, manufacturing, accounts, stores
};
{
char name[15];
int age;
float bs;
enum emp_dept dept;
};
struct employee e1;
clrscr();
strcpy(e1.name,"poonam bajwa");
e1.age=22;
e1.bs=18765.00;
e1.dept=manufacturing;
printf("\n name = %s ",e1.name);
printf("\n age= %d ",e1.age);
printf("\n basic salary = %f",e1.bs);
printf("\n department = %d",e1.dept);
getch();
}
Comments
Post a Comment