Day.01.09 枚举

#include 

int main(int argc, const char * argv[]) {
    // insert code here...
    
    /*
//1.定义枚举的类型
    enum Weekday{
        
        Monday,//后面的值依次加1,初始值为0
        Tuesday,
        Wednesday,
        Thursday,
        Friday
    };
    
    //定义一个枚举变量
    enum Weekday day = Monday;
    
    enum Weekday day1 = Tuesday;
    
    printf("%d\n",day1);
     
    //2.声明枚举类型的同时定义一个枚举变量
    enum Weekday{
        
        Monday,//后面的值依次加1,初始值为0
        Tuesday,
        Wednesday,
        Thursday,
        Friday
    }day;
    
    day = Wednesday;
    */
    //3.省略枚举类型的名字
    
    enum {
        
        Monday,//后面的值依次加1,初始值为0
        Tuesday,
        Wednesday,
        Thursday,
        Friday
    }day;
    
    day = Wednesday;
    
    printf("day = %d\n",day);
    
    int a = 10;
    
    a = 33;//改变了a的值
    
    printf("a = %d\n",a);
    
    const int b = 2;
    
    //b = 22//报错,用const关键字修饰的变量不允许重新赋值,(只读变量)
    
    printf("b = %d\n",b);
    return 0;
}

你可能感兴趣的:(Day.01.09 枚举)