相关疑难解决方法(0)

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, %d\n", birth.year, birth.month, birth.day);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

因为它是一个联合,它会给我4个字节,因为int是这个联合中给出的最高类型.这就是我从阅读中得到的所有内容,我不知道输出为什么

1820, 28, 28
Run Code Online (Sandbox Code Playgroud)

c unions

0
推荐指数
1
解决办法
71
查看次数

标签 统计

c ×1

unions ×1