Enumeration

enum

Enum is a keyword of c programming that holds the constant user define value. If we make a variable with an enum then we can use the same enum to make a new variable. We can set the initial value on it (as we did here in sun 1) and the remaining will go on increasing on that, you also can define or give a specific number to each of them.  

Syntax 

enum identifier {v1, v2.......vn) var-name; 

  • Identifier is user define name  

  • {v1.....vn} is user input constant value, && we also can set a default number  

Code 


#include <stdio.h>
#include <conio.h>
//  enum code to print weekend or working days
enum days
{
    sun = 1,
    mon,
    Tue,
    wed,
    Thu,
    Fri,
    sat
}; // it will start from 1 and go on i++;
void main()
{
    int a;
    enum days d// making a variable of days to check the condition
    printf("enter a value of a from 1-7: ");
    scanf("%d", &a);
    d = a;
    if (d == sat)
    {
        printf("it's a weekend!");
    }
    else
    {
        printf("working day!");
    }
    getch();
}

Output  

Enter a value of a from1-7: 7 

         It's a weekend! 

Follow our page for regular updates.

0 Comments