Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

C

Learn step by step



C-Enumeration

Enumeration type (enum) allows programmers to define their own data type . Keyword enum is used to defined enumerated or user defined data type.

enum type_name{ value1, value2,...,valueN };

Here, type_name is the name of user defined data type or tag. And value1, value2,....,valueN are the values that this data type can hold.

By default, value1 equal to 0, value2 will be 1 and so on, But programmer can also change the default value as mentioned below:

enum suit{
club=0;
diamonds=10;
hearts=20;
spades=3;
};
Declaration of enumerated variable

Above given code defines the type of the data, but not any variable is created. A variable of type enum can be created as:

enum boolean{
false;
true;
};
enum boolean check;

Here, variable check is declared which is of enum boolean type.


#include <stdio.h>
enum week{ sunday, monday, tuesday, wednesday, thursday, friday, saturday};
int main(){
enum week today;
today=wednesday;
printf("%d day",today+1);
return 0;
} RUN

You can write any program in C language without the help of enumerations but, enumerations helps in writing clear codes and simplify programming.



Related Videos