# include <stdio.h>

enum WeekDay
{
    MonDay, TuesDay, WednesDay, ThursDay, FirDay, SaturDay, SunDay
};   //默认从0开始。

int main(void)
{
    enum WeekDay day = TuesDay;
    printf("%d\n", day);   //  结果为 1

    return 0;
}
# include <stdio.h>

enum WeekDay
{
    MonDay = 2, TuesDay, WednesDay, ThursDay, FirDay, SaturDay, SunDay
};   //第一个枚举常量声明绝对值后,其后边按顺序升序

int main(void)
{
    enum WeekDay day = ThursDay;
    printf("%d\n", day);   //  结果为 5

    return 0;
}
# include <stdio.h>

enum WeekDay
{
    MonDay, TuesDay, WednesDay, ThursDay, FirDay, SaturDay, SunDay
}; 

void f(enum WeekDay i)
{
    printf("%d\n", i);
    switch (i)
    {
    case 0:
        printf("MonDay!\n");
        break;
    case 1:
        printf("TuesDay!\n");
        break;
    case 2:
        printf("WednesDay!\n");
        break;
    case 3:
        printf("ThursDay!\n");
        break;
    case 4:
        printf("FirDay!\n");
        break;
    case 5:
        printf("SaturDay!\n");
        break;
    case 6:
        printf("SunDay!\n");
        break;
    }

}

int main(void)
{
    f(MonDay);

    return 0;
}

标签: none

添加新评论