The code defines an enumeration type named direction, which has four constants: East, West, North, and South. The main() function creates an instance of the direction enumeration named dir and initializes it to the constant South. The cout statement then attempts to print the value of dir on the console.
However, this code will not produce the expected output. When we attempt to print an enumeration value using cout, the integer value of the constant is printed, not the name of the constant. To print the name of the constant instead of its integer value, we need to use a switch statement to map the enumeration value to its corresponding name.
#include <iostream> using namespace std; enum direction {East, West, North, South}; int main() { direction dir; dir = South; cout<<dir; return 0; }To download raw file Click Here
3
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions