enum data type

enum data type:

it means enumerated type.
It's a user defined datatype.It's syntax is

enum name{value1,value2,.....valuen);

ex:enum week{sunday,monday,tuesday,wednesday,thursday,friday,saturday}

and afterwards to declare variables of enum type 'name'

enum name variables;

ex:enum week a;

now after doing this we can directly assign the value of a as


the value of a will be 4.Because the compiler will automatically assign the value 0 to sunday,1 to monday and so on..
if we want to change the sequence we can specify as

enum week{sunday=1,monday,tuesday,wednesday,thursday,friday,saturday};

now the compiler will start assigning value to names from 1
that means
if we specify


then 6 will be the output.

we can also specify random values to names like

enum week{sunday=4,monday=5,tuesday=1,wednesday=3,thursday=7,friday=2,sat=6};

and corresponding values of the name will be printed.
let's come to the defenition of enum datatype..
if you refer some books it states as

An enumerated type is an abstract data type used to model an attribute that has a specific number of options (or identifiers)

That means we cannot specify the value other than the specified names declared.
But consider the following program
enum week{sun=4,mon=5,tues=1,wednes=3,thurs=7,friday=2,sat=6};
enum week a;

will print 25 itself.I don't know whether i am correct or not

About This Blog

There is something for everyone. !! A tech blog on various topics. Let it be devops, programming etc; we have it all covered here in layman terms :)

Total Pageviews

Back to TOP