Header Ads Widget

what is Enumerated data types in C

 What is Enumerated data types in C 

(1). It is user define data type in C .

(2). It is used to give names to integer constant.

(3). It makes the program more readable and understandable .

Syntax:-

           


 

Example:-

#include<stdio.h>
enum status {off=0 , on=1};
int main()
{
enum status flag ;
flag =on;
printf("%d",flag); // flag=1
return 0;
}

Example 2:-             


#include<stdio.h>
enum week {mon, tue, wed , thus, fri, sat, sun};
int main()
{
enum week day;
day = fri;
printf("%d",day); // day=4
return 0;
}
Output:-
4

Creation of Enumeration variable;-

 Syntax;-
enum enum_name var_name ;

                                              


Example:-


#include<stdio.h>
enum week {mon, tue, wed , thus, fri, sat, sun};
int main()
{
enum week day;
day = fri;
printf("day no :- %d",day); // day=4
return 0;
}

Recommended Post:

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-




Post a Comment

0 Comments