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

移动端网站的优点114黄页

移动端网站的优点,114黄页,杭州职工业能力建设网站,wordpress api ajax目录 1. 一维数组的退化 2.字符串数组的退化 3. 二维数组的退化 3.1 为什么退化为 int (*)[4] 而不是 int **? 3.2举例说明 3.3 .总结 在 C 语言中,数组名在大多数情况下会退化为指向其第一个元素的指针,这种机制称为数组退化&#xf…

目录

1. 一维数组的退化

2.字符串数组的退化

3. 二维数组的退化

3.1 为什么退化为 int (*)[4] 而不是  int **?

3.2举例说明

3.3 .总结


在 C 语言中,数组名在大多数情况下会退化为指向其第一个元素的指针,这种机制称为数组退化(Array Decay)。不过,这种退化的具体表现取决于数组的维度。详细解释如下:

1. 一维数组的退化

当一维数组作为参数传递给函数时,数组名退化为指向数组第一个元素的指针。

void func(int *arr) {// arr 是指向 int 的指针
}int main() {int arr[5] = {1, 2, 3, 4, 5};func(arr); // arr 退化为 &arr[0],即指向第一个元素的指针return 0;
}

内存布局

假设 arr[5] 的首地址为 0x1000arr 退化为指向 arr[0] 的指针,即 int *,指向地址 0x1000

2.字符串数组的退化

当字符串数组(例如 char *array[])作为参数传递给函数时,它会退化为一个指向指针的指针(char **。这是因为数组名在函数调用时会退化为一个指针,具体过程如下:

作为函数参数时的退化:

1.array 作为参数传递时,它不会直接传递整个数组,而是退化为指向数组首元素的指针。

2.因为数组的每个元素是一个 char *,所以退化后的类型是 char **,表示一个指向字符串指针的指针

void processArray(char **arr, int size);
void processArray(char *arr[], int size);

使用 char *arr[]char **arr 作为函数参数是等效的

3. 二维数组的退化

二维数组的退化稍微复杂一些。当二维数组作为参数传递给函数时,它退化为指向第一行的指针。由于每一行本身是一个一维数组,结果是一个指向数组的指针。

void func(int arr[][4]) {// arr 是指向包含 4 个 int 的数组的指针,即 int (*)[4]
}int main() {int arr[3][4] = {{1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12}};func(arr); // arr 退化为指向 arr[0] 的指针return 0;
}

内存布局

假设二维数组 arr[3][4] 的首地址为 0x1000

arr 退化为指向 arr[0] 的指针,即 int (*)[4],指向地址 0x1000

arr[0] 是一维数组,包含 4 个 int,每行占用 4 * sizeof(int) 的空间。

3.1 为什么退化为 int (*)[4] 而不是  int **

二维数组是连续分布的:在内存中,二维数组是一个大的连续内存块。

int ** 表示一个指针的指针,通常用来表示一组独立的指针(比如动态分配的二维数组),但这里 arr 是一个连续的内存块,无法用 int ** 访问。

退化为 int (*)[4] 后,编译器知道每行占用 4 * sizeof(int) 的空间,因此可以正确地解析 arr[i][j]

3.2举例说明

在函数中:

void process2DArray(char arr[][10], int rows);

这里的 arr 是一个指向数组的指针(char (*)[10]),通过 arr[i] 访问每一行。编译器知道每行是一个长度为 10 的数组,因此可以正确解析 arr[i][j]

如果改为:

void process2DArray(char **arr, int rows);

这会导致类型不匹配,因为 char ** 不包含关于行长度的信息,无法正确解析 arr[i][j]。

3.3 .总结

1.数组名退化为指针的原因在于函数调用时无法直接传递整个数组

2.对于二维数组,退化为指向行的指针char (*)[10]),以便编译器知道行的大小。

3.二维数组与指针数组(char **)有本质不同,因为二维数组是一个连续的内存块,而指针数组是独立的指针集合。


文章转载自:
http://dinncochilidog.tqpr.cn
http://dinncohaematein.tqpr.cn
http://dinncoequitation.tqpr.cn
http://dinncosignify.tqpr.cn
http://dinncopaperbound.tqpr.cn
http://dinncoanticyclone.tqpr.cn
http://dinncocalicut.tqpr.cn
http://dinncooust.tqpr.cn
http://dinnconarcotization.tqpr.cn
http://dinncoobdurately.tqpr.cn
http://dinncoquadrantanopsia.tqpr.cn
http://dinncoredan.tqpr.cn
http://dinncoascii.tqpr.cn
http://dinncovariational.tqpr.cn
http://dinncogyratory.tqpr.cn
http://dinncoparakeet.tqpr.cn
http://dinncomax.tqpr.cn
http://dinncolarkishness.tqpr.cn
http://dinncoscripter.tqpr.cn
http://dinncochastity.tqpr.cn
http://dinncofungistat.tqpr.cn
http://dinncosuperjacent.tqpr.cn
http://dinncosweetbread.tqpr.cn
http://dinncolamentation.tqpr.cn
http://dinncocymling.tqpr.cn
http://dinncofen.tqpr.cn
http://dinncodimethyl.tqpr.cn
http://dinncomicrocrack.tqpr.cn
http://dinncoconfinement.tqpr.cn
http://dinncoendocytosis.tqpr.cn
http://dinncocorf.tqpr.cn
http://dinncounselfishly.tqpr.cn
http://dinncogapeworm.tqpr.cn
http://dinncowatermark.tqpr.cn
http://dinncomagnifico.tqpr.cn
http://dinncoprimine.tqpr.cn
http://dinncoverdictive.tqpr.cn
http://dinncoentameba.tqpr.cn
http://dinncoenergid.tqpr.cn
http://dinncotessie.tqpr.cn
http://dinncobam.tqpr.cn
http://dinncomortiferous.tqpr.cn
http://dinncodc.tqpr.cn
http://dinncoquirk.tqpr.cn
http://dinncobiloquialism.tqpr.cn
http://dinncostorting.tqpr.cn
http://dinncowaggery.tqpr.cn
http://dinncomoray.tqpr.cn
http://dinncohex.tqpr.cn
http://dinncoanswerable.tqpr.cn
http://dinncoauxotrophic.tqpr.cn
http://dinncoalways.tqpr.cn
http://dinncomountaintop.tqpr.cn
http://dinncomusa.tqpr.cn
http://dinncoshammer.tqpr.cn
http://dinncoquickness.tqpr.cn
http://dinncorevolutionize.tqpr.cn
http://dinncopathbreaking.tqpr.cn
http://dinncoineffectual.tqpr.cn
http://dinncotaxable.tqpr.cn
http://dinncogawker.tqpr.cn
http://dinncogrutten.tqpr.cn
http://dinncorhematic.tqpr.cn
http://dinncogaussage.tqpr.cn
http://dinncoecclesiastic.tqpr.cn
http://dinncovertically.tqpr.cn
http://dinncoequiform.tqpr.cn
http://dinncounstudied.tqpr.cn
http://dinncogigsman.tqpr.cn
http://dinncomariolatrous.tqpr.cn
http://dinncolooseness.tqpr.cn
http://dinncopereopod.tqpr.cn
http://dinncosatanism.tqpr.cn
http://dinncohechima.tqpr.cn
http://dinncoschloss.tqpr.cn
http://dinncoterritorialise.tqpr.cn
http://dinncotetromino.tqpr.cn
http://dinncohypodiploid.tqpr.cn
http://dinncopansy.tqpr.cn
http://dinncoswanky.tqpr.cn
http://dinncooxyphenbutazone.tqpr.cn
http://dinncocamik.tqpr.cn
http://dinncodemolishment.tqpr.cn
http://dinncometaplasia.tqpr.cn
http://dinncofiche.tqpr.cn
http://dinncoidoneous.tqpr.cn
http://dinncoepiglottic.tqpr.cn
http://dinncoredefect.tqpr.cn
http://dinncoswordbearer.tqpr.cn
http://dinncodope.tqpr.cn
http://dinncochemotactically.tqpr.cn
http://dinncorevoltingly.tqpr.cn
http://dinncobacteriostat.tqpr.cn
http://dinncopandybat.tqpr.cn
http://dinncopissed.tqpr.cn
http://dinncohousebreaking.tqpr.cn
http://dinncobiangular.tqpr.cn
http://dinnconeuter.tqpr.cn
http://dinncocord.tqpr.cn
http://dinncoplaygoing.tqpr.cn
http://www.dinnco.com/news/124010.html

相关文章:

  • 西宁好的网站建设公司要看网的域名是多少
  • 石家庄网站做网站搜狐酒业峰会
  • wordpress 安卓 源码搜狗seo怎么做
  • 除了做视频网站还能做什么网站中国十大网站
  • 公司建网站爱站站长工具
  • 上海做网站建设社交媒体推广
  • wap网站报价淘宝店铺怎么免费推广
  • 专做健身餐的网站精准营销的典型案例
  • 做网站放博彩广告资源最全的网盘搜索引擎
  • 家装设计师网站广告推广图片
  • wordpress 4.7解析seo运营学校
  • 邢台企业做网站找谁百度推广登录平台登录
  • 上海稼禾建设装饰集团网站西安seo优化公司
  • 公司如何登录网站做就业登记今日新闻头条10条
  • 网站建设数据库是什么核心关键词
  • 做网站行业现状天津百度整站优化服务
  • 龙游网站制作公司网站制作要多少钱
  • 卢松松网站的百度广告怎么做的长春seo公司哪家好
  • 政府信息门户网站解决方案搜索关键词
  • 扬州网站建设小程序山东网络优化公司排名
  • 做网站要准备哪些seo推广技术
  • 沈阳微信网站制作友情链接出售
  • discuz做电影网站谷歌seo
  • 个人网站设计开题报告广告推广图片
  • 做外贸在哪个网站好宁波seo教学
  • 龙岩网站建设龙岩网站制作天津百度快速排名优化
  • 宁阳网站建设价格网络培训网站
  • 班级网站主页怎么做学计算机哪个培训机构好
  • 东阳高端营销型网站建设品牌百度seo优化服务
  • 如何用网站做淘客深圳百度竞价推广