CrazyEngineers
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Ankita Katdare

    AdministratorAug 10, 2011

    @Nikumbh: Sure. What do you want to know about it?
    Are you sure? This action cannot be undone.
    Cancel
  • Nikumbh

    MemberAug 10, 2011

    AbraKaDabra
    @Nikumbh: Sure. What do you want to know about it?
    I want to know what is the use of enumeration tag.
    Are you sure? This action cannot be undone.
    Cancel
  • Nikumbh

    MemberAug 10, 2011

    I want to know the use of enum data type
    Are you sure? This action cannot be undone.
    Cancel
  • Ankita Katdare

    AdministratorAug 10, 2011

    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'.
    Are you sure? This action cannot be undone.
    Cancel
  • Nikumbh

    MemberAug 14, 2011

    Is that necessary to have enum data type....?
    Are you sure? This action cannot be undone.
    Cancel
  • ayusha patnaik

    MemberAug 15, 2011

    can any one suggest me a good and easy book for object oriented programming for c++?
    Are you sure? This action cannot be undone.
    Cancel
  • TheV

    MemberAug 15, 2011

    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<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;
    }
    
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register