[C]union

#include <stdio.h>
#include <string.h>
typedef union Person
{
    char name[10];
    int age;
} pinfo;

int main()
{
    pinfo man1;
    strcpy(man1.name, "Jerry");
    printf("%s
", man1.name); //.name, .age共用一个内存单元,赋值后要立即输出,否则值就没了。并且一次只能对一个union变量赋值
    man1.age = 24;
    printf("%d
", man1.age);
    return 0;
}
原文地址:https://www.cnblogs.com/profesor/p/13053342.html