Enumeration in C++

Enumeration is a user-defined type that value is restricted to one of several explicitly named constants(enumerators). enum is the key word that is use for this. In this code first we declare global enum declaration, in which we have four values and then in main program we can make an instance of enum and then use it.

Source Code

#include <iostream>
using namespace std;
enum number { one = 1, two = 4, three = 9, four = 16};
int main() {
number n;
n = four;
cout<<"\n\n\t ****** Enumeration ******** \n\n";
cout << "Four Square : " << n << endl;
return 0;
}

Output of the Program

Enumeration in C++



Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment