C Programming Enumeration

C Programming Enumeration

In this chapter you will learn how to work with C  programming enumeration. Besides enum, you will also know where it is commonly used in C programming .

C Programming Enumeration

In C programming, enumeration is a user-defined data type that consists of integral constants. enumThe keyword is used to define the enumeration .

				
					enum flag { constant1, constant2, ..., constantN };


				
			

 Here flag is user defined data type

And   constant1 , constant2 ,….,  constantN are values ​​of flag type.

By default constant1   has a value of 0, constant2   has a value of 1 and so on. You can change the default value of the enum element as per your need.

enumThat is, you can change the index of the element if you want .

				
					// change the default value of enum
enum color {
red = 0,
green = 3,
black = 5,
white = 3,
};
				
			

C Program Enum Type Declaration

When you create a variable of type enum, only the blueprint of the variable is created. Below is the method of creating enum type variable

				
					
enum boolean { false, true };
enum boolean security;
				
			

Here enum booleansecurity variable of type is created.

Here the same security variable is created using different syntax .

Leave a Comment

Your email address will not be published. Required fields are marked *