Enum in C Programming Language
In this post, We will learn about enumeration (enum) and its uses.
Example:
In this post, We will learn about enumeration (enum) and its uses.
Introduction
An enumeration is a user-defined data type that consists of integral constants. To define an enumeration, the keyword enum is used. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.
#include<stdio.h>
enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun};
int main()
{
enum week day;
day = Wed;
printf("%d",day);
return 0;
}
Important Points about Enum
- Two enum names can have the same value
- If we do not explicitly assign values to enum names, the compiler by default assigns values starting from 0
- We can assign values to some name in any order
- The value assigned to enum names must be some integral constant
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment