c++英雄联盟

Unions are conceptually similar to structures. The syntax to declare/define a union is also similar to that of a structure. The only differences is in terms of storage. In structure each member has its own storage location, whereas all members of union uses a single shared memory location which is equal to the size of its largest data member.

工会在概念上类似于结构 。 声明/定义联合的语法也类似于结构的语法。 唯一的区别在于存储。 在结构上,每个成员都有其自己的存储位置,而联合的所有成员都使用一个共享存储位置,该位置等于其最大数据成员的大小。

This implies that although a union may contain many members of different types, it cannot handle all the members at the same time. A union is declared using the union keyword.

这意味着,尽管一个联合可以包含许多不同类型的成员, 但它不能同时处理所有成员 。 一名工会是使用声明的union关键字。

union item
{int m;float x;char c;
}It1;

This declares a variable It1 of type union item. This union contains three members each with a different data type. However only one of them can be used at a time. This is due to the fact that only one location is allocated for all the union variables, irrespective of their size. The compiler allocates the storage that is large enough to hold the largest variable type in the union.

这声明了一个union item类型的变量It1 。 该union包含三个成员,每个成员具有不同的数据类型。 但是,一次只能使用其中之一。 这是由于以下事实:所有union变量均仅分配一个位置,而不管其大小如何。 编译器会分配足够大的存储空间以容纳联合中最大的变量类型。

In the union declared above the member x requires 4 bytes which is largest amongst the members for a 16-bit machine. Other members of union will share the same memory address.

在上面声明的联合中,成员x要求4个字节 ,这是16位计算机中成员中最大的。 工会的其他成员将共享相同的内存地址。

在C中访问工会会员 (Accessing a Union Member in C)

Syntax for accessing any union member is similar to accessing structure members,

访问任何union成员的语法类似于访问结构成员的语法,

union test
{int a;float b;char c;
}t;t.a;    //to access members of union t
t.b;
t.c;

实例时间 (Time for an Example)

#include <stdio.h>union item
{int a;float b;char ch;
};int main( )
{union item it;it.a = 12;it.b = 20.2;it.ch = 'z';printf("%d\n", it.a);printf("%f\n", it.b);printf("%c\n", it.ch);return 0;
}

-26426 20.1999 z

-26426 20.1999 z

As you can see here, the values of a and b get corrupted and only variable c prints the expected result. This is because in union, the memory is shared among different data types. Hence, the only member whose value is currently stored will have the memory.

如您所见, ab的值被破坏,只有变量c打印预期结果。 这是因为在联合中,内存在不同的数据类型之间共享。 因此,当前存储其值的唯一成员将具有内存。

In the above example, value of the variable c was stored at last, hence the value of other variables is lost.

在上面的示例中,变量c的值最后被存储了,因此其他变量的值丢失了。

翻译自: https://www.studytonight.com/c/unions-in-c.php

c++英雄联盟

c++英雄联盟_C联盟相关推荐

  1. 在虚幻引擎5中重塑火箭联盟——口袋联盟

    流派:电子学习| MP4 |视频:h264,1280×720 |音频:AAC,44.1 KHz 语言:英语+中英文字幕(根据原英文字幕机译更准确) |大小解压后:3.28 GB |时长:4h 21m ...

  2. APP测试中需要进行广告方面的测试,那什么是网络广告联盟、联盟广告、联盟广告的种类

    网络广告联盟: 又称联盟营销,(又称联盟会员,如中小网站.个人网站.WAP 站点等)组成联盟,通过联盟平台帮助广告主实现广告投放. 一.什么是联盟广告 联盟广告是众多小网站联合起来形成一个统一的广告发 ...

  3. 拥抱人工智能新时代 做真“英雄”还需靠“联盟”

    1956年,当约翰-麦卡锡.马文-明斯基等科学家首次提出"人工智能(AI)"这一术语之时,一定想不到1984年,阿诺德o施瓦辛格以<终结者>形象出现在电影屏幕中时,带给 ...

  4. 怎么在电脑上玩超级英雄联盟 超级英雄联盟电脑版玩法教程

    <超级英雄联盟>是一款集"多元养成"与"即时卡牌"为一体的超萌科幻手游,游戏中有着百位来自各次元的英雄,他们个性十足,帅气.高冷.腹黑.御姐.萝莉. ...

  5. 国外cpa广告联盟EMU-lead-cpa联盟详解(1)英文独立站的搭建

    域名购买及主机 域名购买 网站:https://www.namesilo.com       优惠码:KFC99  输入优惠码去购买可以有优惠 想一个自己要做的网站类型:美食,健康,旅游,运动等等,我 ...

  6. 琅琊领航联盟|TK联盟首期私享会圆满结束

    2022年10月19日TK联盟首期私享会载誉归来,以线下闭门会议的模式举行.全球TikTok TSP服务商.跨境MCN机构.广告一级代理等内部联盟成员机构聚首深圳,共同探讨TikTok市场调研成果.出 ...

  7. 【无限互联】 学院作品: LOL掌上英雄联盟

    一.项目介绍: 我做的项目是LOL英雄掌上联盟(模仿版),是腾讯游戏英雄联盟官方制作的app,来为LOL玩家提供最专业的资讯和社交服务 ,可以查询英雄联盟的最新的情况,这款app的功能有:       ...

  8. 以太联盟 基于区块链技术的角色扮演对战游戏

    以太联盟 是一款基于区块链技术的角色扮演对战游戏.玩家可以通过召唤英雄来为自己战斗从而赢取以太币奖励.每个玩家至多可以派5名英雄_上场.游戏共有5大种族, 5个职业,彼此之间互相克制,另外不同英雄还拥 ...

  9. 世界首个由队伍拥有并运营的CS:GO电竞联盟FLASHPOINT成立

    2020年2月6日,世界上最著名的职业<反恐精英:全球攻势(CS:GO)>队伍联合起来创建了Flashpoint -- 史上第一个由队伍拥有并运营的全球性电子竞技联盟,Gen.G作为其中一 ...

最新文章

  1. 测序仪的序列:DNA测序的历史
  2. 荆门 php,荆门php培训
  3. OutputStreamWriter介绍代码实现
  4. sql的加减乘除运算_SQL简单查询语、运算符学习和练习
  5. 支付宝的一些小问题,注意事项等等,等用得时候在来写写
  6. [html] websocket和socket有什么区别?
  7. 分布式缓存产品Redis和memcached比较区别(图)
  8. XNA or Silverlight for Windows Phone 7 game
  9. microsoft azure
  10. 关于我在(PTA)程序设计类实验辅助教学平台的重修经历
  11. win10手柄震动测试软件,win10系统测试手柄震动频率的操作方法
  12. 蓝牙 穿戴手环通信原理
  13. 王者荣耀android换ios,王者荣耀安卓转ios教程攻略
  14. bugzilla安装
  15. android重力传感器横竖反,Android重力传感器--随重力旋转的图标
  16. 用友U8数据备份实例工作经验
  17. python sed awk_观点|awk sed ,一个老派系统管理员的基本素养
  18. Maperitive地图瓦片切割部分使用方法总结
  19. vscode使用vetur格式化代码
  20. 新浪短域名和百度短域名

热门文章

  1. 2020知到计算机文化基础答案,2021知到网课 创业十步 单元测试答案
  2. 在seo中,怎么写原创文章。
  3. 了解Socket吗?什么是socket?
  4. mib browser打开mib文件
  5. 无人机3d可视化系统的应用是怎样实现的?
  6. harbor登录报错doesn‘t contain any IP SANs问题
  7. 济南大学计算机专硕考研真题,济南大学考研真题各专业汇总
  8. Unity 3D-- 摄像机Clear Flags和Culling Mask属性用途详解
  9. Java专栏学习导图【一】
  10. 如何进行性能测试的调优