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

 Live Demo

#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

Updated on: 23-Mar-2020

357 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements