Hey, folks! Hope you all are doing well. In this article, we will be discussing Enumeration in C .

What is Enumeration?

Enumeration in C is a user-defined data type. Thus, we can customize the data and store it into it according to the needs of the user/system.

Enumeration assigns string or character values i.e. enumeration tags to the integer data values. For every string literal or value, there is an integer index assigned to it as seen below.

Enumeration In CEnumeration In C

Like a C array, enum starts the index values from 0.

Thus, enum helps us to simplify the code and increase the readability of the program.

Now, let us understand the structure of Enumeration in C programming.


Syntax of Enumeration in C

So, now let us have a look at the declaration of Enum in C:

1

**enum** **enum**``-name {enumerators};

  • enum-name: A valid name will be referred for all the enumeration related tasks.
  • enumerators: The named integer literals.

In order to fetch and display the data stored in enum, we need to associate an object to it using the below command:

1

**enum** **enum**``-name object;

Further, to display any data value stored in the enum, we can associate the object to the specified string-literal as shown below:

1

object = enumerator;

Let us now implement the above syntax of enumeration through some examples.

#c programming #c

The Beginners Guide to Enumeration in C
1.30 GEEK