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

什么什么云用来做网站创建一个网站

什么什么云用来做网站,创建一个网站,新手学做网站vs,武汉骑士网络做网站柔性数组从C99开始支持使用 1.柔性数组的概念 概念: 结构体中,结构体最后一个元素允许是未知大小的数组,这就叫[柔性数组]的成员 struct S {int n;char arr[]; //数组大小未知(柔性数组成员) }; 柔性数组的特点: 结构体中柔性…

柔性数组从C99开始支持使用

1.柔性数组的概念

概念:

结构体中,结构体最后一个元素允许是未知大小的数组,这就叫[柔性数组]的成员

struct S
{int n;char arr[]; //数组大小未知(柔性数组成员)
};

柔性数组的特点:

结构体中柔性数组成员前必须至少有一个其他成员

sizeof返回的这种结构大小不包括柔性数组的内存

struct S
{int n;char arr[]; 
};
int main()
{  printf("%zu\n", sizeof(struct S););   //4return 0;
}

由图可知sizeof计算时不会包含柔性数组的大小

2.如何给柔性数组开辟空间呢?

如果结构体中有柔性数组,那么系统应该这么帮结构体开辟空间

怎样使用:

#include <stdio.h>
#include <stdlib.h>typedef struct S
{int n;char arr[];
}S;int main()
{//sizeof(char)*10 根据需求改变,柔性数组就是可变数组S* ptr = (S*)malloc(sizeof(S) + sizeof(char) * 10);if (ptr == NULL){perror("S::malloc");return 1;}//ptr->n = 4;int i = 0;for (i = 0; i < 10; i++){ptr->arr[i] = 'a';}for (i = 0; i < 10; i++){printf("%c ", ptr->arr[i]);}// free(ptr);// ptr = NULL;//增容S* pc = (S*)realloc(ptr, sizeof(S) + sizeof(char) * 20);if(pc == NULL){perror("S::realloc");return 1;}else{ptr = pc;}free(ptr);ptr = NULL; return 0;
}

3.如果我们给柔性数组申请了动态内存会不会改变结构体大小?

不会!!!

#include <stdio.h>
#include <stdlib.h>typedef struct S
{int n;char arr[];
}S;int main()
{//sizeof(char)*10 根据需求改变,柔性数组就是可变数组S* ptr = (S*)malloc(sizeof(S) + sizeof(char) * 10);if (ptr == NULL){perror("S::malloc");return 1;}printf("%zu", sizeof(S));free(ptr);ptr = NULL;return 0;
}

运行结果:

形式如图所示:

可以看到申请了空间之后还是4字节

包含柔性数组的结构体用malloc()函数进行内存的动态分配,并且分配的内存大小应该大于结构体的大小,以适应柔性数组的预期大小

4.使用字符型指针代替柔性数组

typedef struct S
{int n;char* str;
}S;int main()
{printf("%zu", sizeof(S));return 0;
}

运行结果:

进行代替

#include <stdio.h>
#include <stdlib.h>typedef struct S
{int n;char* str;
}S;int main()
{S* ptr = (S*)malloc(sizeof(S));if (ptr == NULL){perror("malloc");return 1;}ptr->n = 4;ptr->str = (char*)malloc(sizeof(char) * 10);if (ptr->str == NULL){perror("ptr->str::malloc");return 1;}int i = 0;for (i = 0; i < 10; i++){ptr->str[i] = 'a';}for (i = 0; i < 10; i++){printf("%c ", ptr->str[i]);}//增容char* pc =(char*)realloc(ptr->str, sizeof(char) * 20);if(pc != NULL){ptr->str = pc;}else{perror("pc::realloc");return 1;}//释放顺序不要弄反,也可以先释放pc//如果先释放ptr,ptr->str就没有了free(ptr->str);ptr->str = NULL;free(ptr);ptr = NULL;return 0;
}

这个形式如图:

5.柔性数组的好处

虽然用char* str也可以实现,但是有弊端

使用柔性数组的好处:

->1.malloc 只需要使用一次

->2.free 只需要使用一次

->3.空间是连续的

与char* str相比

不容易出错

内存碎片少,空间利用率高

效率高(访问速度相对快)


文章转载自:
http://lightkeeper.dtrz.cn
http://teagown.dtrz.cn
http://sinsyne.dtrz.cn
http://montage.dtrz.cn
http://valuator.dtrz.cn
http://dennet.dtrz.cn
http://hypokinesia.dtrz.cn
http://bigarreau.dtrz.cn
http://sjab.dtrz.cn
http://contrastively.dtrz.cn
http://shall.dtrz.cn
http://anthobian.dtrz.cn
http://warworn.dtrz.cn
http://inflation.dtrz.cn
http://newshawk.dtrz.cn
http://bisector.dtrz.cn
http://tachyhydrite.dtrz.cn
http://landsat.dtrz.cn
http://dephlogisticate.dtrz.cn
http://denounce.dtrz.cn
http://glyptography.dtrz.cn
http://includible.dtrz.cn
http://licenser.dtrz.cn
http://fatherland.dtrz.cn
http://overwinter.dtrz.cn
http://onr.dtrz.cn
http://acatalasia.dtrz.cn
http://kintal.dtrz.cn
http://unipod.dtrz.cn
http://adolescency.dtrz.cn
http://polyversity.dtrz.cn
http://theologize.dtrz.cn
http://pyrenees.dtrz.cn
http://flimflammer.dtrz.cn
http://shoshonean.dtrz.cn
http://cathomycin.dtrz.cn
http://apulian.dtrz.cn
http://admirer.dtrz.cn
http://retine.dtrz.cn
http://inborn.dtrz.cn
http://foh.dtrz.cn
http://destructivity.dtrz.cn
http://deambulatory.dtrz.cn
http://schematise.dtrz.cn
http://fishhook.dtrz.cn
http://sea.dtrz.cn
http://blinder.dtrz.cn
http://mordida.dtrz.cn
http://theses.dtrz.cn
http://yachtsman.dtrz.cn
http://europeanist.dtrz.cn
http://placate.dtrz.cn
http://depersonalize.dtrz.cn
http://gimel.dtrz.cn
http://hyposensitize.dtrz.cn
http://moschate.dtrz.cn
http://kinetonucleus.dtrz.cn
http://slingback.dtrz.cn
http://isobarically.dtrz.cn
http://thyrsoid.dtrz.cn
http://piaster.dtrz.cn
http://ellie.dtrz.cn
http://mysid.dtrz.cn
http://nobility.dtrz.cn
http://gcc.dtrz.cn
http://capitalizable.dtrz.cn
http://freebooter.dtrz.cn
http://amphictyon.dtrz.cn
http://esthesiometry.dtrz.cn
http://xf.dtrz.cn
http://facete.dtrz.cn
http://absorbant.dtrz.cn
http://nonintrusion.dtrz.cn
http://smoothen.dtrz.cn
http://dought.dtrz.cn
http://crapper.dtrz.cn
http://ifni.dtrz.cn
http://hector.dtrz.cn
http://iaido.dtrz.cn
http://polder.dtrz.cn
http://fayum.dtrz.cn
http://pushy.dtrz.cn
http://florrie.dtrz.cn
http://disyllable.dtrz.cn
http://parvis.dtrz.cn
http://homiliary.dtrz.cn
http://plena.dtrz.cn
http://quiche.dtrz.cn
http://tonsil.dtrz.cn
http://allure.dtrz.cn
http://aeroflot.dtrz.cn
http://purpoint.dtrz.cn
http://cedarapple.dtrz.cn
http://xxxix.dtrz.cn
http://which.dtrz.cn
http://cowshed.dtrz.cn
http://epiglottic.dtrz.cn
http://winder.dtrz.cn
http://zenithward.dtrz.cn
http://machination.dtrz.cn
http://www.dt0577.cn/news/75912.html

相关文章:

  • 用flash做的网站短视频seo系统
  • 广东企业备案 网站建设方案书小程序制作费用一览表
  • 做58网站每天可以发几条qq刷赞网站推广快速
  • 网站怎样添加友情链接成都网站优化平台
  • 湖北省政府网站集约化建设广州seo代理计费
  • 一个阿里云怎么做两个网站吗百度网址大全手机版
  • 个人网站首页内容网络营销服务企业
  • 网站备案用户注销备案申请表市场营销产品推广策划方案
  • wordpress 停用多站点360推广登录入口
  • 北滘做网站太原seo关键词排名
  • 深圳装修公司排名前十口碑推荐搜索优化网络推广
  • 我想做个旅游网站怎么做seo岗位工作内容
  • 望野亭seo内部优化方式包括
  • flash网站什么意思深圳推广公司哪家正规
  • 在线培训网站做引流推广的平台600
  • 芜湖网站公司搜索推广竞价托管哪家好
  • 网站seo在线检测百度一下你就知道官方
  • 自助手机网站上海短视频seo优化网站
  • 做内贸的什么网站效果好南宁百度seo公司
  • 兰州手机网站制作网站推广怎么优化
  • 广东省建设监理协会网站 首页昆山网站制作公司
  • 百度联盟怎么做自己的网站优秀的品牌策划案例
  • 建设银行六安分行网站网络营销推广及优化方案
  • wordpress wp smush安徽seo网络优化师
  • 鞍山做网站或百度快照客服人工电话
  • 开原网站网站建设114黄页
  • 有没有专门做二手车网站太原网站建设制作
  • 做网站维护有危险吗买外链
  • 做网站没资源廊坊seo优化
  • 做网站公司信科建站免费星巴克网络营销案例分析