
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
- Related Articles
- What are enumerated data types in C++?
- How to define an enumerated type (enum) in C++?
- What are Enumerated Constants in C++?
- What is data type of FILE in C?
- What type of language is python?
- What are primary data types in C language?
- What are implicit and explicit type conversions in C language?
- What are primitive data type in C++?
- Enumerated Types or Enums in C++
- What are different types of data in C language?
- What is BLOB data type in MySQL?
- What is TEXT data type in MySQL?
- What is malloc in C language?
- What is Calloc in C language?
- What is Realloc in C language?

Advertisements