首页 > 代码库 > ENUM枚举学习

ENUM枚举学习

示例1:
#include "stdio.h"
void main()
{
enum {Mon, Tue, Wed, Thr, Fri, Sat, Sun};
printf("Mon = %d\n", Mon);
printf("Tue = %d\n", Tue);
printf("Wed = %d\n", Wed);
printf("Thr = %d\n", Thr);
printf("Fri = %d\n", Fri);
printf("Sat = %d\n", Sat);
printf("Sun = %d\n", Sun);

printf("-----------\n");

//枚举相当于是个常量集,相当于一下操作
#define MON 0
#define TUE 1
#define WED 2
#define THR 3
#define FRI 4
#define SAT 5
#define SUN 6
printf("MON = %d\n", MON);
printf("TUE = %d\n", TUE);
printf("WED = %d\n", WED);
printf("THR = %d\n", THR);
printf("FRI = %d\n", FRI);
printf("SAT = %d\n", SAT);
printf("SUN = %d\n", SUN);
}


示例2:
#include <stdio.h>

enum
{
Qi=1,//企划部
Cai,//财务部
Ren,//人力资源部
Shi,//市场部
};

main()
{
int n;

printf("1-企划部,2-财务部,3-人力资源部,4-市场部\n");
printf("请输入:");
scanf("%d",&n);

printf("你输入的是:");
switch(n)
{
case 1:
printf("企划部\n");
break;
case 2:
printf("财务部\n");
break;
case 3:
printf("人力资源部\n");
break;
case 4:
printf("市场部\n");
break;
}
}

ENUM枚举学习