C语言-枚举(enum)和联合(union)

使用enum进行定义

/*
枚举类型演示
*/
#include <stdio.h>
int main() {
    enum /*季节*/ {CHUN, XIA = 5, QIU, DONG}; 
    printf("QIU是%d\n", QIU); 
}

使用union联合进行定义

/*
联合演示
*/
#include <stdio.h>
typedef union{
    int val; 
    float fval1; 
} tmp; 
int main(){
    tmp utmp = {0}; 
    printf("&(utmp.val)是%p\n", &(utmp.val)); //所指向的地址是相同的
    printf("&(utmp.fval)是%p\n", &(utmp.fval1)); 
}

猜你喜欢

转载自www.cnblogs.com/hyq-lst/p/12426310.html