#include <stdio.h>
int main(int argc, const char * argv[]) {
//1)先定义枚举类型,在定义枚举变量
enum iColor{
kIcolorWhite,//0
kIcolorBlack = 3,//1 3
kIcolorGolden//2 4
//kIcolorWhite + 1 = kIcolorBlack...
};
enum iColor iPhoneColor;
//2)定义枚举类型同时,定义枚举变量
enum Sex{
kSexMan,//0
kSexWomen,//1
kSexTrajsvestite//2
} isex;
iPhoneColor = kIcolorBlack;
isex = kSexTrajsvestite;
printf("%d\n",iPhoneColor);
printf("%d\n",isex);
printf("%d\n",kIcolorGolden);
struct Person{
char *name;
enum Sex isex;//限定赋值
};
iPhoneColor = 1;//避免
printf("%d\n",iPhoneColor);
return 0; |
|