Files
C_code/C语言/翁凯C语言/8/联合.c
T
Serendipity 93c16edb5a 更新MD文件路径引用
- 修正主README.md中的所有路径引用,使其与当前文件结构一致
- 更新翁凯C语言学习指南链接路径
- 更新五子棋AI项目文档链接路径
- 更新数据结构学习文档链接路径
- 修正编译说明和学习模块使用指南中的目录路径
- 改进五子棋README.md的编译运行说明,增加Windows和Linux/macOS的分平台指导
- 确保所有文档链接和路径引用都能正确工作
2025-10-17 10:52:27 +08:00

34 lines
516 B
C

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
// !联合
/*
1.存储
所有的成员共享一个空间
同一时间只有一个成员是有效的
union的大小是其最大的成员
2.初始化
对第一个成员做初始化
*/
typedef union {
int i;
char ch[sizeof(int)];
} CHI;
int main()
{
CHI chi;
int i;
chi.i = 1234;
for ( i=0; i<sizeof(int); i++)
{
printf("%02hhx", chi.ch[i]);
}
printf("\n");
return 0;
}