C program to demonstrate enum datatype

      Enum(enumeration) is a user defined datatype(enum datatype) that consists of set of integral constants. By default the constants with in enum hold values 0 … 1 and so on. The values of constants in enum can be chaged during declaration.

enum datatype program in c



Source Code :

#include<stdio.h>
enum days {Mon, Tues, Wed, Thurs, Fri, Sat, Sun };   //Step 1
int main()
{
    enum days start, end;                            //Step 2
    start= Tues; /* means start=1 */                 //Step 3
    end= Sat; /* means end=5 */                      //Step 4
    printf("\n start = %d, end = %d", start,end);    //Step 5
    start= 64;                                       //Step 6
    printf("\n start now is equal to %d", start);    //Step 7
    return 0;
}


edit-code-image

Output:

1.  start = 1, end = 5
    start now is equal to 64

Explanation:

Step 1: The enum ‘days’ is created using the enum keyword with inegral constants as days with in a week.

Step 2: The enum varaibles are declared with names ‘start’ and ‘end’.

Step 3: The enum varaibles are assigned to some of the integral constants of the enum ‘days’. So the enum variables will get some integer value.

Step 4: The value corresponding to the enum variable is printed on the output screen using printf() function.

Step 5: New value is assigned to the varaible ‘start’.

Step 6: The new value of the variable ‘start’ is printed on the output screen using printf() function.

More Insights:

1. Enum data type .

1. More about enum data type.

More Content : Explore More