code.club

標題: 有關列舉 enum [打印本頁]

作者: enter    時間: 2015-4-29 16:21
標題: 有關列舉 enum
如下例是可以執行的:

#include <stdio.h>

int main(void){

enum color_type { red, green, white,pink,black=2,blue};

enum color_type mycolor;

mycolor = white;
printf("%d\n", mycolor); // 2

mycolor = black;
printf("%d\n", mycolor); //2

mycolor = pink;
printf("%d\n", mycolor); //3

mycolor = blue;
printf("%d\n", mycolor); //3

return 0;
}



作者: enter    時間: 2015-4-29 16:23
#include <stdio.h〉

int main(void){

enum stype { zero, one, two, three, four};

enum stype sss; // 一定要有一次是用enum開頭
sss=one;

typedef enum stype gtype;
gtype sss; // 這裡因為上面typedef已有enum所以這裡可以直接用 dtype來設定sss。
sss=one;

return 0;
}




歡迎光臨 code.club (http://code.club/) Powered by Discuz! X3.2