2024年10月15日 12:54

This commit is contained in:
许大仙 2024-10-15 04:54:46 +00:00
parent 6e44509fe2
commit c4a6d56829
3 changed files with 8 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 MiB

View File

@ -201,6 +201,14 @@ int main() {
> * ① 共用体使用了内存覆盖技术,同一时刻只能保存一个成员的值,如果对新的成员赋值,就会把原来成员的值覆盖掉。
> * ② 给共用体变量中的成员赋值的时候,尽量每次只给一个成员赋值,防止产生数据覆盖现象!!!
* 共用体和结构体是不一样,结构体可能是这样的(不考虑内存对齐),如下所示:
![](./assets/1.png)
* 但是,共用体在内存中却是这样的(不考虑内存对齐),如下所示:
![](./assets/2.gif)
* 示例: