枚举与联合体

来源:互联网 发布:php extract函数 编辑:程序博客网 时间:2024/06/06 13:04
#include <stdio.h>                                      //枚举
                                                         

enum NUM
{
ZERO,
ONE,
TWO,
THREE,
TEN = 10,
ELEVEN
};


int main()
{
    printf("%d %d %d %d %d %d\n", ZERO, ONE, TWO, THREE, TEN, ELEVEN);


    return 0;

}


#include <stdio.h>       //联合体


union demo
{
    int a;
    char ch[4];
};


int main()
{
    union demo d;
    d.a = 0x12345678;


    int i;
    for (i = 0; i < 4; i++)
    {
        printf("%d\n", d.ch[i]);
    }


    return 0;
}

原创粉丝点击