什么是枚举?
-----把一个事物所有可能的取值一一列举出来。
枚举的优缺点?
-----代码更安全,但是书写麻烦
#include<stdio.h> enum WeekDay { MonDay,TuesDay,WednesDay,ThursDay,FriDay,SaturDay,SunDay }; void f(enum WeekDay i) { switch(i) { case 0: printf("MonDay! "); break; case 1: printf("TuesDay! "); break; case 2: printf("WednesDay! "); break; case 3: printf("ThursDay! "); break; case 4: printf("FriDay! "); break; case 5: printf("SaturDay! "); break; case 6: printf("SunDay! "); break; } } int main(void) { //int day;//day定义成int类型不合适 //enum WeekDay day=WednesDay; f(MonDay); return 0; }