Enumeration

Enumeration (or enum) is a user-defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.

Syntax

enum  nameOfEnum {
varName1 = 1, varName2 = 0
};

Example:

The below example demonstrates the use of enumeration (enum) in C++.

C++




// Program to demonstrate working
// of enum in C++
  
#include <iostream>
using namespace std;
  
enum week { Mon, Tue, Wed, Thur, Fri, Sat, Sun };
  
int main()
{
    enum week day;
  
    day = Wed;
  
    cout << day;
  
    return 0;
}


Output

2

User Defined Data Types in C++

Data types are means to identify the type of data and associated operations of handling it. improve. In C++ datatypes are used to declare the variable. There are three types of data types:

  1. Pre-defined DataTypes
  2. Derived Data Types
  3. User-defined DataTypes

In this article, the User-Defined DataType is explained:

Similar Reads

User-Defined DataTypes

The data types that are defined by the user are called the derived datatype or user-defined derived data type. These types include:...

1. Class

A Class is the building block of C++ that leads to Object-Oriented programming is a Class. It is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. A class is like a blueprint for an object....

2. Structure

...

3. Union

A Structure is a user-defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type....

4. Enumeration

...

5. Typedef

Like Structures , Union a user-defined data type. In union, all members share the same memory location. For example in the following C program, both x and y share the same location. If we change x, we can see the changes being reflected in y....

Conclusion

...

Contact Us