C Programming: enumeration data types
Another feature present in c programming is enumeration data type, the user can define their won data types with won defined values. To achieve this the "enum" keyword is used and it help a lot. user defined data types are give access to programmer define their values according to requirements, But it does not allow the integer constants to define with enum keyword.
For example consider 12 months of ab year
enum month{ Jan,fen,Apr,may,jun,Jul,rug,sep,Oct,Nov,Dec};
the above statement creates a user defined data type. the keyword enum is followed by the tag name month.The enum values are constant unsigned integers and starts form "0". The identifier Jan refers to zero, Feb to 1 and so on. The identifier are not to be enclosed within quotation marks.
The following program demonstrates enum data type in c
#include< stdio.h> void main() { int i; enum month {JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,DEC}; clrscr(); for(i=0;i<=11;i++) printf("\n%d",i); }
No comments:
Post a Comment