enum类型的变量定义为一个字节存储

#include <stdio.h>
//给枚举类型限定字节数,只能在C++11模式下运行
typedef enum weekday: unsigned char {
    SUN, MON, TUE, WED, THU, FRI, SAT
} weekday_t;

int main() {
    weekday_t weekday = MON;
    printf("%d\n", sizeof (weekday_t));
    printf("%d\n", sizeof (weekday));
    return 0;
}



你可能感兴趣的:(enum类型的变量定义为一个字节存储)