Enumerators in C

Enumeration is a user defined datatype in C language. It is used to assign names to integral constants which makes a program easy to read and maintain.

The keyword "enum" is used to declare an enumeration.

Syntax: enum enum_name {const1, const2,…....constn};

By default, const1 is 0, const2 is 1 and so on. You can change default values of enum elements during declaration.

Example: enum  fruits{apple,mango,orange,grapes};

Example1. An example program to demonstrate working

Example2. Enum in switch statement

Example3. Enum with loop


Popular Posts