enum in c

Sahil Ali
3 min readSep 9, 2023
Photo by Bernard Hermant on Unsplash

You must have seen the word enum if you have done any programming.As we all know there is 32 keyword in c, enum is also one of them..

Screenshot from Programming in ANSI C book by E Balaguruswamy | screenshot by author

But what is this actually?
Just as there is a user-defined function in every programming, in the same way, there is a user-defined function as well as a user-defined data type.

This means that an enum is a user-defined data type in C that consists of a set of named integer constants. Also known as Enumerations.

General form:

enum identifier_name {value1, value2,…….valuen};

Here.. identifier_name is a user-defined enumerated data type that can be used to declare a variable.

enum DaysOfWeek {
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
};

Here names of weeks like SUNDAY, MONDAY… are known as enumeration constant. By default, the first constant (SUNDAY) is assigned the value 0, and subsequent constants are assigned values in increasing order.

Using Enumerations

--

--

Sahil Ali

SDE | SIH’22 Finalist | Gold Medalist | MERN Stack | Exploring Tech & Science | Website & AI Tools | Resolving Error | https://www.linkedin.com/in/sahilali20/