Enumeration is a collection of constant it is created by using enum keyword. Many a times programmers deal with data items which represent some attributes of the object being modeled.
For example, let us consider an attribute – color. The possible values of this attribute could be BLACK, WHITE, RED, BLUE, GREEN, MAGENTA, CYAN, and YELLOW.
A programmer may create an array of characters to store these values. However, this approach requires that these values are treated as character array elements, whereas the programmer would like to treat these values as integers, which obviously is more convenient. Enumeration data type allows such values to be treated as integers constants.
Syntax:
enum datatype_name
{
dataitem_1,dataitem_2,…dataitem_n
);
EX: WAP for give numbering using enum
#include<stdio.h> #include<conio.h> main() { enum month{ jan,feb,mar,apr,may,jun,jul }; typedef enum month m; m m1,m2; clrscr(); m1=mar; printf("m1 = %d",m1); printf("Enter value for m2 "); scanf("%d",&m2); printf("m2 = %d",m2); getch(); } Output m1 = 2
Enter value for m2 = 3
M2 = 3
It is used to define new datatype using exixting datatype.
Syntax: typedef<existingdatatype> <new datatype>
Example
1.typedef int number; number a; 2.typedef struct employee emp; emp e;