0% found this document useful (0 votes)
11 views1 page

Enumarartions in C

Uploaded by

dhavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Enumarartions in C

Uploaded by

dhavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Enumarations:

* These are used to assign names to integer constants.


* "enum" keyword is used to create an enumaration.
* enumaration must have name, is called as datatype.
* program contains enumarations will improve readability.
syntax:
enum name{name1,name2,name3,....};

1.enumaration with default values:


* default values for enumaration begins with 0
* assign integer values to names in increment order.
ex:
enum days{mon,tus,wed,thr,fri,sat,sun};
printf("%d",mon); //0

2.enumaration with user specified start value:


* first name is assigned with a value
* next names will be by default assigned values in increment order.
ex:
enum days{mon=1,tus,wed,thr,fri,sat,sun};
printf("%d",mon); //1

3.enumaration with user specified values for each name:


ex:
enum nums{one=1,five=5,seven=7,ten=10};

4.enumaration with custom ranges:


* one set of names will have one sequence of numbers
* another set of names will have another sequence of numbers.
ex:
enum nums{one=1,two,three,four,seven=7,eight,nine,ten};

5.Mulitple enumaration in program:


* enumaration defined with name having value can't used in another enumaration
in same program.
ex:
enum bool{true=1,false=0};
enum res{true=0,false=1}; // error true is already defined.

You might also like