我正在进入C和我试验联盟。我的代码如下: #include <stdio.h>
union date {
int year ;
char month;
char day ;
};
int main() {
union date birth;
birth.year = 1984;
birth.month = 7;
birth.day = 28;
printf("%d, %d
我听说过的工会是它将为其中最大的变量分配内存空间。在这里,我试图用两种不同的方式分配“相同”的价值,但结果是有问题的。 首先, union h {
int a;
char b;
};
int main()
{
union h h1;
h1.b = 'X';
printf("%d %c\n",h1.a, h1.b);
return
考虑工会的成员都有一个共同的基类: struct Base {
int common;
};
struct DerivedA : Base {};
struct DerivedB : Base {};
union Union {
DerivedA a;
DerivedB b;
};
无论什么联盟“包含”在运行时(即,什么最后存储的值),只要它包含的东