Advertisement
enum Fruit {apple, pineapple, watermelon}
//C++ Enumeration example
#include<iostream>
using namespace std;
enum Cities
{
Frankfurt, NewYork, Sydney, Tokyo //enumeration's enumerators/constants
};
int main()
{
cout<< Frankfurt <<"\n";
cout<< NewYork <<"\n";
cout<< Sydney <<"\n";
cout<< Tokyo;
}
0
1
2
3
//C++ Enumeration example
#include<iostream>
using namespace std;
//Anonymous enumeration
enum
{
Frankfurt, NewYork, Sydney, Tokyo //enumeration's enumerators/constants
};
int main()
{
cout<< Frankfurt <<"\n";
cout<< NewYork <<"\n";
cout<< Sydney <<"\n";
cout<< Tokyo;
}
0
1
2
3
Advertisement
//C++ Enumeration example
#include<iostream>
using namespace std;
//Enumeration
enum Cities
{
Frankfurt, NewYork, Sydney, Tokyo //enumeration's enumerators/constants
};
int main()
{
//Creating two new enumerators of type Cities, outside its scope
Cities LasVegas, Berlin;
//But by default, these enumerators are given random int values
cout<< LasVegas << "\n";
cout<< Berlin << "\n";
//Assigning these enumerators the values of pre-defined enumerators
Berlin = Frankfurt;
LasVegas = NewYork;
//Printing the new values assigned to the two new enumerators
cout<< Berlin <<"\n";
cout<< LasVegas << "\n";
//Creating a new enumerator and initializing it with a value of enumerator NewYork
Cities Atlanta = NewYork;
cout<< Atlanta <<"\n";
}
4201083
2686824
0
1
1
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement