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
ex:a=friday;
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
a=friday;
printf(%d”,a);
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
#include<stdio.h>
#include<conio.h>
{
enum week{sun=4,mon=5,tues=1,wednes=3,thurs=7,friday=2,sat=6};
enum week a;
a=25;
printf(%d”,a);
getche()
}
will print 25 itself.I don’t know whether i am correct or not



Amen
- Feb 17th, 08
well!best of Luck aadi for ur blog and site
admin
- Feb 17th, 08
thanks man