CodesJava

Easy learning with example program codes

CPP Enumeration


Enum is a data type defined in CPP library that can include fixed set of static and implicit constants like days of the week, directions etc.

Advantages of using Enum:

  • Improves type safety.
  • Can be easily used in switch.
  • Can be traversed.
  • Can have fields, constructors and methods.
  • May implement many interfaces but cannot extend any class because it internally extends Enum class.

Example:

#include <iostream.h>  
using namespace std;  
enum directions { North, South, East, West };  
int main()  
{  
directions direction;  
direction = East;  
cout << "Direction: " << direction+1 <<endl;  
return 0;  
}

Output

Direction: 3
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki