Computer >> Computer tutorials >  >> Programming >> C++

Enumerated Types or Enums in C++


In this tutorial, we will be discussing a program to understand Enumerated types or Enums in C++.

Enumerated types are user-defined data types in which the user can specify a limited number of values that can be allocated to the variable.

Example

#include <bits/stdc++.h>
using namespace std;
int main(){
   //defining enum variable
   enum Gender {
      Male,
      Female
   };
   Gender gender = Male;
   switch (gender) {
      case Male:
         cout << "Gender is Male";
         break;
      case Female:
         cout << "Gender is Female";
         break;
      default:
         cout << "Value can be Male or Female";
   }
   return 0;
}

Output

Gender is Male