- #include <stdio.h>
- int main()
- {
- //定义枚举
- enum Day
- {
- MORNNING, //注意是逗号,且默认从0开始
- MOON,
- AFTERNOON=7, //将枚举常量重新定义一个值
- NIGHT,
- };
- enum Day date=MORNNING; //定义一个枚举变量并初始化赋值
- printf("MORNNING=%d\n",date);
- date=MOON;
- printf("MOON=%d\n",date);
- date=AFTERNOON;
- printf("AFTERNOON=%d\n",date);
- date=NIGHT;
- printf("NIGHT=%d\n",date);
- int a=0;a=1;
- printf("a=%d\n",a);
- //上面等价于下面的
- enum KAIGUAN
- {
- CLOSE,
- OPEN,
- };
- enum KAIGUAN KAI=OPEN;
- printf("OPEN=%d\n",KAI);
- return 0;
- //同一个作用域内,即使枚举类型不一致,也不能出现重复的枚举常量
- }
|
|