What's the advantage of creating a variable of enum
type? I know how to define an enum type, and a variable - however, I don't quite see the advantage?
#include <stdio.h>
int main(void){
enum colour{
white,
red=2,
green,
blue,
yellow,
black
} jacket;
jacket=50;
int shirt=yellow;
printf("%d\n",jacket);
printf("%d",shirt);
return 0;
}
In the above code, jacket
is defined as enum
but shirt
is defined as an integer. The enum
type doesn't prevent me from using a value that isn't specified as an element. Nor does the integer
type prevent me from assigning it to a value from the enum
type.
The above code gives the following output:
50
5
What's the functionaly difference, if any, between these variables?