

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use enums in C/C++?
Enumeration is a user defined datatype in C language. It is used to assign names to the integral constants, which makes a program easy to read and maintain. The keyword “enum” is used to declare an enumeration.
Here is the syntax of enum in C language,
enum enum_name{const1, const2, ....... };
The enum keyword is also used to define the variables of enum type. There are two ways to define the variables of enum type as follows.
enum week{sunday, monday, tuesday, wednesday, thursday, friday, saturday}; enum week day;
Here is an example of enum in C language,
Example
#include<stdio.h> enum week{Mon=10, Tue, Wed, Thur, Fri=10, Sat=16, Sun}; enum day{Mond, Tues, Wedn, Thurs, Frid=18, Satu=11, Sund}; int main() { printf("The value of enum week: %d\t%d\t%d\t%d\t%d\t%d\t%d\n\n",Mon , Tue, Wed, Thur, Fri, Sat, Sun); printf("The default value of enum day: %d\t%d\t%d\t%d\t%d\t%d\t%d",Mond , Tues, Wedn, Thurs, Frid, Satu, Sund); return 0; }
Output
The value of enum week: 10111213101617 The default value of enum day: 0123181112
- Related Questions & Answers
- How to use enums in C++?
- How to use enums in Python classes?
- How to map C++ enums to strings?
- Java Program to use == operator to compare enums
- Enumerated Types or Enums in C++
- Enums in Rust Programing
- What is the syntax to define enums in javascript?
- How do we compare the members of enums in Java?
- How to list all the classes, interfaces, and enums in JShell in Java 9?
- How to use LINQ in C#?
- How to use StringBuilder in C#?
- How to use XmlSerializer in C#?
- How to use namespaces in C++?
- How to use Selenium in C#?
- What are the limitations of MySQL ENUMs?
Advertisements