//枚举
//枚举(列举所有的情况),限定值的取值范围,保证取值的安全性
1
#include<stdio.h>
2
#include<stdlib.h>
3
4
enum Day
5
{
6
Monday,
7
Tuesday,
8
Wednesday,
9
Thursday,
10
Friday,
11
Saturday,
12
Sunday
13
};
14
15
void main() {
16
enum Day d = Tuesday;
17
printf("%#x,%d\n",&d,d);
18
getchar();
19
}
也就是说 把这个值限定在范围内
也能这么做
1
#include<stdio.h>
2
#include<stdlib.h>
3
enum Day
4
{
5
Monday=10,
6
Tuesday=20,
7
Wednesday=30,
8
Thursday=40,
9
Friday=50,
10
Saturday=60,
11
Sunday=70
12
};
13
void main() {
14
enum Day d = Tuesday;
15
printf("%#x,%d\n",&d,d);
16
getchar();
17
}