測試完才發現我下面代碼寫的不規范,那個枚舉裡面的幾種類型必須為全部大寫字母
1、非賦值的枚舉類型
[html]
#include "stdio.h"
enum weekday
{ sun,mon,tue,wed,thu,fri,sat } a,b,c;
main(){
a=sun;
b=mon;
c=tue;
enum weekday d ,e ,f;
d = wed;
e = thu;
f = fri;
printf("%d,%d,%d,%d,%d,%d\n",a,b,c,d,e,f);
}
輸出:
[html]
pateo@pateo-B86N53X:~/work/study$ cc main.c -o main
pateo@pateo-B86N53X:~/work/study$ ./main
0,1,2,3,4,5
2、賦值的起始枚舉
[html]
#include "stdio.h"
enum weekday
{ sun=0x0009,mon,tue,wed,thu,fri,sat } a,b,c;
main(){
a=sun;
b=mon;
c=tue;
enum weekday d ,e ,f;
d = wed;
e = thu;
f = fri;
printf("%d,%d,%d,%d,%d,%d\n",a,b,c,d,e,f);
}
輸出:
[html]
pateo@pateo-B86N53X:~/work/study$ cc main.c -o main
pateo@pateo-B86N53X:~/work/study$ ./main
9,10,11,12,13,14
3、賦值特殊
[html
#include "stdio.h"
enum weekday
{ sun=0x0009,mon,tue,wed=0x0003,thu,fri,sat } a,b,c;
main(){
a=sun;
b=mon;
c=tue;
enum weekday d ,e ,f;
d = wed;
e = thu;
f = fri;
printf("%d,%d,%d,%d,%d,%d\n",a,b,c,d,e,f);
}
輸出:
[html]
pateo@pateo-B86N53X:~/work/study$ cc main.c -o main
pateo@pateo-B86N53X:~/work/study$ ./main
9,10,11,3,4,5
4、重復特殊
[html]
#include "stdio.h"
enum weekday
{ sun=0x0009,mon=5,tue,wed=0x0003,thu=7,fri=2,sat=9 } a,b,c;
main(){
a=sun;
b=mon;
c=tue;
enum weekday d ,e ,f ,g;
d = wed;
e = thu;
f = fri;
g = sat;
printf("%d,%d,%d,%d,%d,%d,%d\n",a,b,c,d,e,f,g);
}
輸出:
[html]
pateo@pateo-B86N53X:~/work/study$ cc main.c -o main
pateo@pateo-B86N53X:~/work/study$ ./main
9,5,6,3,7,2,9