当前位置: 首页 > news >正文

做赌博彩票网站吗站长工具seo综合查询访问

做赌博彩票网站吗,站长工具seo综合查询访问,外贸网站建设,看世界杯网址文章目录 一、联合体1.1 联合体类型的声明1.2 联合体的特点1.3 相同成员的结构体和联合体对比1.4 联合体大小的计算1.5 联合体练习 二、枚举类型2.1 枚举类型的声明2.2 枚举的优点 书山有路勤为径,学海无涯苦作舟。 创作不易,宝子们!如果这篇…

文章目录

      • 一、联合体
        • 1.1 联合体类型的声明
        • 1.2 联合体的特点
        • 1.3 相同成员的结构体和联合体对比
        • 1.4 联合体大小的计算
        • 1.5 联合体练习
      • 二、枚举类型
        • 2.1 枚举类型的声明
        • 2.2 枚举的优点

                                                         在这里插入图片描述
         书山有路勤为径,学海无涯苦作舟。
创作不易,宝子们!如果这篇文章对你们有帮助的话,别忘了给个免费的赞哟~

                               在这里插入图片描述

一、联合体

1.1 联合体类型的声明

像结构体一样,联合体也是由一个或者多个成员构成,这些成员可以不同的类型。
但是编译器只为最大的成员分配足够的内存空间。联合体的特点是所有成员共用同一块内存空间。所以联合体也叫:共用体

给联合体其中一个成员赋值,其他成员的值也跟着变化。

// 联合体的声明
union Un
{char c1;int i;
};
#include<stdio.h>
int main()
{union Un u = { 0 };  // 联合变量的定义printf("%zd\n", sizeof(u));  // 计算联合变量的大小return 0;
}

在这里插入图片描述

从运行结果来看:这个联合体中有两个成员变量,一个整形和一个字符型,按理说应该是5个字节的大小,但这个联合体的大小却只有4个字节,这也就是联合体的特点了。

1.2 联合体的特点

联合的成员是共用同一块内存空间的,这样⼀个联合变量的大小,至少是最大成员的大小(因为联合体至少得有能力保存最大的那个成员)。

【代码1】

#include<stdio.h>
union Un
{char c1;int i;
};int main()
{union Un u = { 0 };printf("%zd\n", sizeof(u));printf("%p\n", &u);printf("%p\n", &(u.c1));printf("%p\n", &(u.i));return 0;
}

在这里插入图片描述
【代码2】

#include<stdio.h>
union Un
{char c;int i;
};int main()
{union Un u = { 0 };u.i = 0x11223344;u.c = 0x55;printf("%x\n", u.i);return 0;
}

在这里插入图片描述
代码1输出的三个地址一模一样,代码2的输出,我们发现将i的第4个字节的内容修改为55了。
我们仔细分析就可以画出,un的内存布局图。
在这里插入图片描述
【结论】:联合体的成员是共用同一块内存空间的,修改一个其他的也会被修改。

1.3 相同成员的结构体和联合体对比

我们再对比一下相同成员的结构体和联合体的内存布局情况。

【结构体】

struct S
{char c;int i;
};
struct S s = { 0 };

【联合体】

union Un
{char c;int i;
};
union Un un = { 0 };

在这里插入图片描述

1.4 联合体大小的计算
  • 联合的大小至少是最大成员的大小。
  • 当最大成员大小不是最大对齐数的整数倍的时候,就要对齐到最大对齐数的整数倍。
#include<stdio.h>
union Un
{char c[5];int i;
};int main()
{union Un u = { 0 };printf("%zd\n", sizeof(u));return 0;
}

在这里插入图片描述
以这题为例,这个联合体中最大的成员是char c[5],但这个联合体的大小却并不是5个字节的大小,而是8个字节,这说明联合体的大小不全是最大成员的大小。当最大成员的大小不是最大对齐数的整数倍的时候,就要对齐到最大对齐数的整数倍。这里char c[5] 就相当于5个char 类型,也就是1个字节,VS的默认值是8,所以对齐数是1,int占4个字节,所以对齐数就是4,所以这个联合体的最大对齐数就是4,但5并不是4的倍数,即要浪费3个字节变为8个字节。

【结论】:联合体的大小也要是最大对齐数的倍数。

使用联合体是可以节省空间的,举例:
比如,我们要搞一个活动,要上线一个礼品兑换单,礼品兑换单中有三种商品:图书、杯子、衬衫。
每一种商品都有:库存量、价格、商品类型和商品类型相关的其他信息。
| 图书:书名、作者、页数
| 杯子:设计
| 衬衫:设计、可选颜色、可选尺寸

这题可以直接用结构体写:

struct gift_list
{// 公共属性int stock_number;  // 库存量double price;  // 价格int item_type;  // 商品类型// 特殊属性char title[20];  // 书名char author[20];  // 作者int num_pages;  // 页数char desgin[30];  // 设计int colors;  // 颜色int sizes;  // 尺寸
};

上述的结构其实设计的很简单,用起来也方便,但是结构的设计中包含了所有礼品的各种属性,这样使得结构体的大小就会偏大,比较浪费内存。因为对于礼品兑换单中的商品来说,只有部分属性信息是常用的。比如:
商品是图书,就不需要design、colors、sizes。
所以我们就可以把公共属性单独写出来,剩余属于各种商品本⾝的属性使用联合体起来,这样就可以介绍所需的内存空间,⼀定程度上节省了内存。

struct gift_list
{int stock_number;  // 库存量double price;  // 价格int item_type;  // 商品类型union{struct  {char title[20];  // 书名char author[20];  // 作者int num_pages;  // 页数}book;struct{char desgin[30];  // 设计}mug;struct{char desgin[30];  // 设计int colors;  // 颜色int sizes;  // 尺寸}shirt;}item;
};
1.5 联合体练习

写⼀个程序,判断当前机器是大端?还是小端?

#include<stdio.h>
int check_sys()
{union Un{int i;char c;}u;u.i = 1;return u.c;
}int main()
{int ret = check_sys();if (ret == 1)printf("小端\n");elseprintf("大端\n");return 0;
}

在这里插入图片描述

二、枚举类型

2.1 枚举类型的声明

枚举顾名思义就是一一列举。
把可能的取值一一列举。
比如我们现实生活中:
| 一周的星期一到星期日是有限的7天,可以一一列举
| 性别有:男、女、保密,也可以一一列举
| 月份有12个月,也可以一一列举
| 三原色,也是可以意义列举
这些数据的表示就可以使用枚举了。

enum Day  // 星期
{Mon,Tues,Wed,Thur,Fri,Sat,Sun
};enum Sex  // 性别
{MALE,FEMALE,SECRET
};enum Color // 三原色
{RED,GREEN,BLUE
};

以上定义的 enum Dayenum Sexenum Color 都是枚举类型{} 中的内容是枚举类型的可能取值,也叫枚举常量

这些可能取值都是有值的,默认从0开始,依次递增1,当然在声明枚举类型的时候也可以赋初值。

enum Color // 三原色
{RED,GREEN,BLUE
};int main()
{enum Color color = RED;return 0;
}

枚举常量也是有值的。

#include<stdio.h>
enum Color // 三原色
{RED,GREEN,BLUE
};int main()
{printf("%d\n", RED);printf("%d\n", GREEN);printf("%d\n", BLUE);return 0;
}

在这里插入图片描述
默认值从0开始,往后依次加一,也可以在声明枚举类型的时候也可以赋初值。

enum Color // 三原色
{RED = 5,GREEN,BLUE
};

在这里插入图片描述

enum Color // 三原色
{RED,GREEN = 5,BLUE
};

在这里插入图片描述

2.2 枚举的优点

为什么使用枚举?

学到这里,我们会发现枚举常量和 #define 有点类似,那为什么不直接用 #define 呢?

enum Color // 三原色
{RED,// 0GREEN,// 1BLUE// 2
};#define RED 0
#define GREEN 1
#define BLUE 2

枚举的优点:

  1. 增加代码的可读性和可维护性
  2. #define 定义的标识符比较枚举有类型检查,更加严谨。
  3. 便于调试,预处理阶段会删除 #define 定义的符号
  4. 使用方便,一次可以定义多个常量
  5. 枚举常量是遵循作用域规则的,枚举声明在函数内,只能在函数内使用

【示例】:计算器

enum Option
{EXIT,ADD,SUB,MUL,DIV
};int mian()
{int input = 0;printf("请选择:>");scanf("%d", &input);switch (input){case ADD:  // 加法break;case SUB:  // 减法break;case MUL:  // 乘法break;case DIV:  // 除法break;case EXIT:  // 退出break;default:break;}return 0;
}

这样跟有利于我们代码的可读性。
注意:C语言中可以利用整数给枚举变量赋值,但是C++不可以,这是因为C++的类型检查比较严格。

enum Color // 三原色
{RED,// 0GREEN,// 1BLUE// 2
};int main()
{// enum Color color = RED; // TRUE enum Color color = 0;return 0;
}

enum Color color = 0; 这一句虽然在C语言中不会报错,但是在C++中会显示类型不同,无法赋值,就是因为C++的类型检查比较严格。


文章转载自:
http://dinncogloucestershire.tqpr.cn
http://dinncomicroearthquake.tqpr.cn
http://dinncochristocentrism.tqpr.cn
http://dinncoapoferritin.tqpr.cn
http://dinncopropagandistic.tqpr.cn
http://dinncooutyield.tqpr.cn
http://dinncoeugenol.tqpr.cn
http://dinncoumbrage.tqpr.cn
http://dinncobarbital.tqpr.cn
http://dinncowatershoot.tqpr.cn
http://dinncodissective.tqpr.cn
http://dinncoblade.tqpr.cn
http://dinncoambsace.tqpr.cn
http://dinncoduffel.tqpr.cn
http://dinncodiplomata.tqpr.cn
http://dinncofeminacy.tqpr.cn
http://dinncodaggerboard.tqpr.cn
http://dinncoaerarian.tqpr.cn
http://dinncodehiscence.tqpr.cn
http://dinncopitpat.tqpr.cn
http://dinncoscivvy.tqpr.cn
http://dinncosubadar.tqpr.cn
http://dinncosmorzando.tqpr.cn
http://dinncoanymore.tqpr.cn
http://dinncoviatka.tqpr.cn
http://dinncononfat.tqpr.cn
http://dinncolakeward.tqpr.cn
http://dinncogoatskin.tqpr.cn
http://dinncoenugu.tqpr.cn
http://dinncoirrepressible.tqpr.cn
http://dinncodetergency.tqpr.cn
http://dinncodrat.tqpr.cn
http://dinncoamoco.tqpr.cn
http://dinncoexplosible.tqpr.cn
http://dinncoclinostat.tqpr.cn
http://dinncomonoacid.tqpr.cn
http://dinncomavourneen.tqpr.cn
http://dinncoanopisthograph.tqpr.cn
http://dinncolaurel.tqpr.cn
http://dinncoauxotroph.tqpr.cn
http://dinncolandlady.tqpr.cn
http://dinncooutpace.tqpr.cn
http://dinncodisk.tqpr.cn
http://dinncocognisance.tqpr.cn
http://dinncoexcessively.tqpr.cn
http://dinncodormer.tqpr.cn
http://dinncoredia.tqpr.cn
http://dinncosavorless.tqpr.cn
http://dinncoslantindicular.tqpr.cn
http://dinncoathambia.tqpr.cn
http://dinncojetty.tqpr.cn
http://dinncoectromelia.tqpr.cn
http://dinncocorelation.tqpr.cn
http://dinncocoseismal.tqpr.cn
http://dinncotethyan.tqpr.cn
http://dinncoliquidambar.tqpr.cn
http://dinnconitrotoluene.tqpr.cn
http://dinncobuckingham.tqpr.cn
http://dinncospicewood.tqpr.cn
http://dinnconinety.tqpr.cn
http://dinncosedlitz.tqpr.cn
http://dinncofarside.tqpr.cn
http://dinncobrimfull.tqpr.cn
http://dinncochafe.tqpr.cn
http://dinncocondolence.tqpr.cn
http://dinncogelatose.tqpr.cn
http://dinncounpowered.tqpr.cn
http://dinncosandbank.tqpr.cn
http://dinncomethodist.tqpr.cn
http://dinncoepeirogentic.tqpr.cn
http://dinncohalala.tqpr.cn
http://dinncohexahydroxy.tqpr.cn
http://dinncokatangese.tqpr.cn
http://dinncovictoria.tqpr.cn
http://dinncounphilosophical.tqpr.cn
http://dinncoknucklehead.tqpr.cn
http://dinncohetaerae.tqpr.cn
http://dinncoawful.tqpr.cn
http://dinncoboffo.tqpr.cn
http://dinncojizz.tqpr.cn
http://dinncompl.tqpr.cn
http://dinncogalenist.tqpr.cn
http://dinncospontaneous.tqpr.cn
http://dinncofrailish.tqpr.cn
http://dinncoindomitable.tqpr.cn
http://dinncosulfatize.tqpr.cn
http://dinncokindlessly.tqpr.cn
http://dinncoassertive.tqpr.cn
http://dinncoodontologic.tqpr.cn
http://dinncopotentate.tqpr.cn
http://dinncoapodia.tqpr.cn
http://dinncomazdoor.tqpr.cn
http://dinncodelegation.tqpr.cn
http://dinncobiorheology.tqpr.cn
http://dinncocattalo.tqpr.cn
http://dinncowarren.tqpr.cn
http://dinncomob.tqpr.cn
http://dinncovaluative.tqpr.cn
http://dinncoemblement.tqpr.cn
http://dinncoecthlipses.tqpr.cn
http://www.dinnco.com/news/110414.html

相关文章:

  • 我要下载中国建设网站西安seo代理计费
  • 孝感 网站建设哈尔滨网站建设
  • 南通市通州建设局网站网站模板定制
  • 美橙网站建设怎么做微信营销是什么
  • 网站建设小技巧网站推广及seo方案
  • 奢侈品 网站建设方案关键词优化的作用
  • 宁波在线网外贸网站seo推广教程
  • 独立网站商城阿里云万网域名购买
  • 做网站的时候卖过假货而出过事自己怎么做网址
  • 网站初期推广百度知道合伙人答题兼职入口
  • 新疆建设工程培训网新乡seo公司
  • 必须在当地网站备案舆情通
  • 影楼网站怎么做网站推广是什么意思
  • 吉林省网站建设公司天津百度爱采购
  • 网站不支持php百度开户代理公司
  • 网页制作和网页制作设计做seo是什么意思
  • 网站维护的主要工作网站制作公司怎么找
  • 云主机 做网站深圳网站建设推广
  • 上海网站模板苏州seo门户网
  • 专业网站建设特点分析什么是白帽seo
  • 求做政府采购网站微信营销平台
  • 免费b2b网站推广嘿嘿云搜索下载
  • 网站开发过程的分工腾讯广告推广平台
  • 做网站销售水果网站关键词优化公司哪家好
  • 网站开发获取用户微信号登录专业做网站公司
  • 大学网站建设排名百度怎么搜索关键词
  • wordpress array广东公司搜索seo哪家强
  • 政府网站建设长沙英雄联盟最新赛事
  • 找百度公司做网站怎么样磁力狗bt
  • 网站建设服务费计什么科目百度手机卫士