
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What are Enumerated Constants in C++?
An enumerated type declares an optional type name and a set of zero or more identifiers that can be used as values of the type. Each enumerator is a constant whose type is the enumeration. These are also called as enumerated constants.
For example, if you are creating an application that has a fixed number of types for some variable. For example, let's say gender, it can be of three types male, female and others. You can define and use an enum like −
#include<iostream> using namespace std; enum Gender {MALE, FEMALE, OTHERS}; int main() { Gender gen = Gender.FEMALE; return 0; }
By default, the value of the first name is 0, the second name has the value 1, and the third has the value 2, and so on. But these values don't matter because enums are basically used to have a symbolic meaning. Whenever you compare an enum in your program, you'd be just using its symbolic meaning and not its actual value.
- Related Articles
- What are enumerated data types in C++?
- What are constants in C++?
- What are C++ Integer Constants?
- What are C++ Character Constants?
- What are C++ Floating-Point Constants?
- What are different types of constants in C++?
- What are Backslash character constants in C language?
- What is enumerated data type in C language?
- What are different types of constants in C language?
- Are there constants in JavaScript?
- What are the constants with an example in C language?
- What are constants in Kotlin and how to create them?
- Explain Enumerated Types in JavaScript.
- Enumerated Types or Enums in C++
- What are various inbuilt methods used to access constants database in scipy.constants() module?
