- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is enumerated data type in C language?
These are used by the programmers to create their own data types and define what values the variables of these datatypes can hold.
The keyword is enum.
Syntax
The syntax for enumerated data type is as follows −
enum tagname{ identifier1, identifier2,…….,identifier n };
Example
Given below is an example for enumerated data type −
enum week{ mon, tue, wed, thu, fri, sat, sun };
Here,
- Identifier values are unsigned integers and start from 0.
- Mon refers 0, tue refers 1 and so on.
Example
Following is the C program for enumerated data type −
#include<stdio.h> main ( ){ enum week {mon, tue, wed, thu, fri, sat, sun}; printf ("Monday = %d", mon); printf ("Thursday = %d", thu); printf ("Sunday = %d", sun); }
Output
When the above program is executed, it produces the following result −
Monday = 0 Thursday =3 Sunday =6
Here, enum identifier can assigned initial value.
Example
Given below is the another C program for enumerated data type −
#include<stdio.h> main ( ){ enum week {mon=1, tue, wed, thu, fri, sat, sun}; printf ("Monday = %d", mon); printf ("Thursday = %d", thu); printf ("Sunday = %d", sun); }
Output
When the above program is executed, it produces the following result −
Monday = 1 Thursday =4 Sunday =7
Advertisements
To Continue Learning Please Login
Login with Google