限制取值范围,只能取所给出的数值(枚举常量),只能给整形,不可给浮点数、字符串等。
#include<stdio.h>
//mon = 1, tue = 2,wed = 3, thu = 4, fri = 5, sat = 6, sun = 7
enum week{ mon = 1, tue = 2, wed = 3, thu = 4, fri = 5, sat = 6, sun = 7 };
int main()
{
enum week xq; //1 2 3 4 5 6 7
xq = 1;
printf("%d\n", xq);
return 0;
}