Enumeration in C Language

Hello friends how are you, today in this blog i will teach you what is Enumeration, syntax of enumeration, how enumeration works and many programs of enumeration in a very simple way.

Let's start

1.It is a collection of named integer constant.
2.It is a user defined data type.
3.enum keyword is used to create a enumeration.
4.Default value of enum's elements are starts with 0 for example suppose that there are four elements in enum like sunday , monday , tuesday and wednesday then here value of sunday is 0, monday is 1, tuesday is 2 and wednesday is 3.
5.But we can also change the default value of enum's element which we discuss later in this post.



enum week {sunday,monday,tuesday,wednesday,thrusday,friday,saturday};
1.enum is a keyword.
2.week is the name of enum and it is a user defined data type.
3.sunday,monday,tuesday,wednesday,thrusday,friday,saturday are the values of enum.
Default value of enum's member
Default value of sunday is 0
Default value of monday is 1
Default value of tuesday is 2
Default value of wednesday is 3
Default value of thrusday is 4
Default value of friday is 5
Default value of saturday is 6
For better understanding see the below example.

enum week {sunday,monday,tuesday,wednesday,thrusday,friday,saturday};
int main()
enum week obj;
printf("Value of wednesday=%d",obj);
### Output ###
Value of wednesday=3

๐Ÿ‘‰We can also change the default value of member of enum. See the example below

enum Age {Ravi=20,Shyam=25,Rocky=18,Daniel=22,Lina=16};
int main()
enum Age student;
printf("Age of Lina is %d",student);
### Output ###
Age of Lina is 16

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 


Post a Comment