C语言的枚举类型有哪些?
C语言的枚举类型:如果一个变量你需要几种可能存在的值,那么就可以被定义成为枚举类型。之所以叫枚举就是说将变量或者叫对象可能存在的情况也可以说是可能的值一一例举出来。
枚举的说明与结构和联合相似, 其形式为:
enum 枚举名{
标识符[=整型常数],
标识符[=整型常数],
...
标识符[=整型常数],
} 枚举变量;
如果枚举没有初始化, 即省掉"=整型常数"时, 则从第一个标识符开始, 顺次赋给标识符0, 1, 2, ...。但当枚举中的某个成员赋值后, 其后的成员按依次加1的规则确定其值。
枚举变量只能取枚举说明结构中的某个标识符常量

/**//************************************************************
Copyright(C),1998-2006,Rx.Co.,Ltd.
FileName:mainApp.cpp
Author:longronglin
Version:1.0
Date:2006-10-06
Description:
FunctionList:
1.intmain()
History:
<author><time><version><desc>
longronglin2006/10/081.0modifyxxx.
***********************************************************/

#include<stdio.h>



/**//*
*返回1为正确执行
*主函数
*
*/

intmain()

...{
//默认起始为0,我这里设置为1。以后递增。可以为负。

enumdayOfWeek...{Mon=1,Tue,Wed,Thu,Fri,Sat,Sun};

enumdayOfWeekdayNum;

inti;

dayNum=Fri;

printf("Wedis%ddayOfWeek ",Wed);


printf("Friis%ddayOfWeek ",dayNum);

i=0;
i=dayNum+1;

printf("iis%d ",i);

return(1);
}

本文地址:
http://www.45fan.com/a/question/68208.html