Example program using enum in c


enum is a User Defined datatype in C

  • An enumerated data type is another user defined type which provides a way of attaching names to numbers to increase simplicity of the code.
  • It uses enum keyword which automatically enumerates a list of words by (indexing )assigning them values 0, 1, 2,..etc.


enum  identifier { enumerator constants list }
constants which are separated by comma

Example – 1

enum  color {red,green,yellow,black }

By default
red constant indexing 0  value
green constant indexing 1  value
yellow constant indexing 2  value
black  constant indexing 3  value

Example – 2

enum  day  {sun, mon, tue=10,wed, thur, fri, sat}

sun constant indexing 0  value
mon constant indexing 1  value
tue  constant indexing  by us 10 value  so next
wed constant indexing  11 value
Thur constant indexing  12 value

Example – 3

enum month{jan, feb, mar=23, april, may=50, june, july}


Jan constant indexing 0  value so  feb  constant value is  1
mar constant indexing 23  value so april constant  value is  24
may constant indexing 50 so June 51 and july 52 …

write Example  Program in C of enum

source code of enum

Output of enum example program  in C

Enter any number from 0 to 5
Your Selected Number is Three


enum Example program in C++

enum Example program in JAVA

(Visited 72 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

Reload Image