前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C语言——enum

C语言——enum

作者头像
用户4645519
发布2020-09-07 11:05:57
4860
发布2020-09-07 11:05:57
举报
#include<stdio.h>

enum Season
{
    spring, summer=100, fall=96, winter
};


typedef enum
{
    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}Weekday;

int main(void)
{

    char * files[] = {"f","b","d","g"};

    printf("sizeof files = %d\n",sizeof(files));
    
    printf("sizeof int = %d\n",sizeof(int));
    
    char *p = NULL;
    printf("sizeof p = %d\n",sizeof(p));
    
    /* Season */

    printf("%d \n", spring); // 0

    printf("%d, %c \n", summer, summer); // 100, d

    printf("%d \n", fall+winter); // 193

    enum Season mySeason=winter;

    if(winter==mySeason)

        printf("mySeason is winter \n"); // mySeason is winter

    int x=100;

    if(x == summer)

        printf("x is equal to summer\n"); // x is equal to summer

    printf("%d bytes\n", sizeof(spring)); // 4 bytes

    /* Weekday */

    printf("sizeof Weekday is: %d \n", sizeof(Weekday)); //sizeof Weekday is: 4

    Weekday today = Saturday;

    Weekday tomorrow;

    if(today == Monday)

        tomorrow = Tuesday;

    else

        tomorrow = (Weekday) (today + 1); //remember to convert from int to Weekday
    
    return 0;
}
sizeof files = 16
sizeof int = 4
sizeof p = 4
0
100, d
193
mySeason is winter
x is equal to summer
4 bytes
sizeof Weekday is: 4


Terminated with return code 0
Press any key to continue ...
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-08-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档