enumeration data type in c and c++

Can anyone tell about the enumeration data type in c and c++....................................... 😒
i.e., enum

Replies

  • Ankita Katdare
    Ankita Katdare
    @Nikumbh: Sure. What do you want to know about it?
  • Nikumbh
    Nikumbh
    AbraKaDabra
    @Nikumbh: Sure. What do you want to know about it?
    I want to know what is the use of enumeration tag.
  • Nikumbh
    Nikumbh
    I want to know the use of enum data type
  • Ankita Katdare
    Ankita Katdare
    Very well, 'Enum' data type variables takes values which have been previously declared.
    With an Enum, you can specify a number of valid values for that variable and descriptive constant names for the values of the Enum. These values are used instead of constants.

    In C:

    For example:

    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.
    It consists of a set of values, jan to dec. Numerically, jan is given the value 1, feb the value 2, and so on.
    The variable 'this_month' is declared to be of the same type as 'month'.
  • Nikumbh
    Nikumbh
    Is that necessary to have enum data type....?
  • ayusha patnaik
    ayusha patnaik
    can any one suggest me a good and easy book for object oriented programming for c++?
  • TheV
    TheV
    I am explain a little more..

    When we write a number of related constant with sequencial values like I want to assign names of the color(red,green,yellow,white,black,blue,orange) with 1 to 7 then instead of writing ..

    int red=1;
    int green =2;
    int yellow =3;
    ........
    ........
    int orange = 7;
    we write ....

    enum color{
    red,green,yellow,white,black,blue,orange
    };
    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
    the first color i.e. red to 1 and the remaining automatically initializes from 2 to 7 . As..
    enum color{
    red=1,green,yellow,white,black,blue,orange
    };
    Again explaining little more...if we initialize green to 1 ie green =1 then the remaining 5 color will have 2 to 6
    eg-

    #include
    #include
    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;
    }
    

You are reading an archived discussion.

Related Posts

There is very little information about the campus selection process of Tata Elxsi on the internet. If someone has appeared for their interview, please share your experience. I have got...
Steam turbines are designed for specific output. The input i.e. steam at designed pressure & temperature if increased by say 10% whether the output will increase by same percentage ?
An electricity generator when operated at more than rated load; increases its winding temperature which restricts its continuous operation at higher load.Most of the new generation generators are hydrogen cooled....
I believe the selection procedure of Syntel is same as that of other companies: 1) Aptitude Test 2) Technical Interview 3) HR Interview I have got some placement paper questions....
What is the campus selection procedure for Sapient? I heard it visits campus very rarely. Could someone post their experience? Find some aptitude test paper questions here: You can also...