[C]enum类型

 

#include <stdio.h>

typedef enum {FALSE, TRUE} Boolean;

Boolean isEven(int i) {
    if ( i % 2 == 0 )
        return TRUE;
    else return FALSE;
}

int main() {
    int i = 10;
    printf("%d\n", isEven(i));
    return 0;
}

 

 

#include <stdio.h>

typedef enum {MON=1, TUE, WED, THU, FRI, SAT, SUN} days_of_week;

int main() {
    days_of_week d = SUN;
    switch (d) {
        case SUN: case SAT: printf("%s\n", "weekend"); break;
        default: printf("weekdays\n");
    }
    return 0;
}

 

posted @ 2020-07-09 20:46  profesor  阅读(114)  评论(0编辑  收藏  举报