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:
- Pre-defined DataTypes
- Derived Data Types
- User-defined DataTypes
In this article, the User-Defined DataType is explained:
Contact Us