enumeration data type in c and c++
i.e., enum
Administrator • Aug 10, 2011
Member • Aug 10, 2011
I want to know what is the use of enumeration tag.AbraKaDabra@Nikumbh: Sure. What do you want to know about it?
Member • Aug 10, 2011
Administrator • Aug 10, 2011
enum month { jan=1, feb=2, mar=3, apr=4, may=5, jun=6, jul=7, aug=8, sep=9, oct=10, nov=11, dec=12 }; enum month this_month; this_month = aug;Here 'month' is declared as the enumerated data type.
Member • Aug 14, 2011
Member • Aug 15, 2011
Member • Aug 15, 2011
int red=1;we write ....
int green =2;
int yellow =3;
........
........
int orange = 7;
enum color{here we didnot initialize any color with any number. It is automatically initialize from 0 to 6. But we want to initialize from 1 to 7 so we just initialize
red,green,yellow,white,black,blue,orange
};
enum color{Again explaining little more...if we initialize green to 1 ie green =1 then the remaining 5 color will have 2 to 6
red=1,green,yellow,white,black,blue,orange
};
#include<stdio.h> #include<conio.h> main() { enum color{ red=1,green=1,yellow,white,black,blue,orange }; enum color mycolor = white; printf("%d",mycolor); printf("%d%d",red,orange); //We can also print by their name . getch(); return; }