Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

C Programming Enumeration

An enumeration in C programming defines a user-defined data type consisting of integral constants that are given names. The enum keyword is used to define an enumerated data type, where type_name is the name and value1, value2 etc. are the values of that type. By default, values are assigned incrementally starting from 0, but the programmer can change the default values. Variables can then be declared of the enumerated type, such as declaring a variable check of type enum boolean. Enumerations help write clearer code and simplify programming.

Uploaded by

slspa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

C Programming Enumeration

An enumeration in C programming defines a user-defined data type consisting of integral constants that are given names. The enum keyword is used to define an enumerated data type, where type_name is the name and value1, value2 etc. are the values of that type. By default, values are assigned incrementally starting from 0, but the programmer can change the default values. Variables can then be declared of the enumerated type, such as declaring a variable check of type enum boolean. Enumerations help write clearer code and simplify programming.

Uploaded by

slspa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C Programming Enumeration

An enumeration is a user-defined data type consists of integral constants and each integral constant is give a
name. Keyword enum is used to defined enumerated data type.
enum type_name{ value1, value2,...,valueN };

Here, type_name is the name of enumerated data type or tag. And value1, value2,....,valueN are values of
type type_name.
By default, value1 will be equal to 0, value2 will be 1 and so on but, the programmer can change the default
value.
// Changing the default value of enum elements
enum suit{
club=0;
diamonds=10;
hearts=20;
spades=3;
};

Declaration of enumerated variable


Above code defines the type of the data but, no any variable is created. Variable of type enum can be created as:
enum boolean{
false;
true;
};
enum boolean check;

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

Example of enumerated 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;
}

Output

4 day

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

You might also like