zoukankan      html  css  js  c++  java
  • C语言——enum

    #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
    ",sizeof(files));
        
        printf("sizeof int = %d
    ",sizeof(int));
        
        char *p = NULL;
        printf("sizeof p = %d
    ",sizeof(p));
        
        /* Season */
    
        printf("%d 
    ", spring); // 0
    
        printf("%d, %c 
    ", summer, summer); // 100, d
    
        printf("%d 
    ", fall+winter); // 193
    
        enum Season mySeason=winter;
    
        if(winter==mySeason)
    
            printf("mySeason is winter 
    "); // mySeason is winter
    
        int x=100;
    
        if(x == summer)
    
            printf("x is equal to summer
    "); // x is equal to summer
    
        printf("%d bytes
    ", sizeof(spring)); // 4 bytes
    
        /* Weekday */
    
        printf("sizeof Weekday is: %d 
    ", 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 ...
    
  • 相关阅读:
    写在寒假
    Docker安装Redis(两种方式)
    JVM类加载机制
    RabbitMQ学习
    MySQL索引详解
    Java内存区域
    Window10下的Docker Desktop安装(保姆级教程)
    JVM垃圾回收
    力扣Hot100(目前进度89/100)
    C# 发送邮件实例
  • 原文地址:https://www.cnblogs.com/CodeWorkerLiMing/p/12007454.html
Copyright © 2011-2022 走看看