CPP Language / Enumerations / enum

It is a user defined data type in CPP. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.

Program Output

#include
enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun};

int main()
{
enum week day;
day = Wed;
printf("%d",day);
return 0;
}

Output
2

Explanation
Default values
Mon=0, Tue=1, Wed=2, Thur=3, Fri=4
Sat=5, Sun=6


enum State {Working = 1, Failed = 0, Freezed = 0};
int main()
{
printf("%d, %d, %d", Working, Failed, Freezed);
return 0;
}

1, 0, 0


Home     Back