union

2024-01-03 15:40:09

union的变量共用内存.

#include <stdio.h>



typedef struct Leix{
    char profession;//职业
    int height;
    union{
        int score ;
        char* course;};
}Leix;

int main(){
    /*初始化student*/
    Leix student={'t',171,90};
    /*初始化teacher*/
    Leix teacher;
    teacher.profession='t';
    teacher.course="Chinese";
    teacher.score=91;

    printf("teacher profession:%c,course=%s,score=%d",teacher.profession,teacher.course,teacher.score);
    

    return 0;
}

文章来源:https://blog.csdn.net/weixin_46855342/article/details/135361627
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。