enum color {
RED = 1,
GREEN = 2,
BLUE = 3
};
void test2(enum color c){
switch (c) {
case RED:
printf("red...");
break;
case GREEN:
printf("red...");
break;
case BLUE:
printf("blue...");
break;
default:
break;
}
}
测试代码:
enum color c = RED;
test2(c);
枚举中第一个值如果没有赋值,默认值为0,后面的值在前一的基础上加1
enum DIRECTION {UP,DOWN=10,LEFT,RIGHT};
printf("up=%d\n",UP);
printf("down=%d\n",DOWN);
printf("left=%d\n",LEFT);
printf("right=%d\n",RIGHT);
程序输出结果如下:
up=0
down=10
left=11
right=12
该博客教程视频地址:http://geek99.com/node/1021
原文出处:http://geek99.com/node/878#