枚举类型
C语言提供了一种类型,这种类型的变量的取值被限定在一定的范围之内。
定义:
enum 枚举类型名{枚举值1,枚举值2...};
举例:
定义一个变量,保存星期数
enum weekday{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday};
定义人的性别
enum Sex{Man,Women};
枚举变量定义:
1) enum weekday{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday};
enum weekday a,b,c;
2) enum weekday{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}a,b,c;
赋值:
a = Monday;
b = Wednesday;
|
|