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

那个网站做网站托管免费cms建站系统

那个网站做网站托管,免费cms建站系统,wordpress pdf view,政府网站建设应做什么数组面试题解析 字符数组 (一) 我们上一篇文章学习了一维数组的面试题解析内容和字符数组的部分内容,我们这篇文章讲解一下字符数组和指针剩余面试题的解析内容,那现在,我们开始吧。 我们继续看一组字符数组的面试…

数组面试题解析

字符数组

(一)

我们上一篇文章学习了一维数组的面试题解析内容和字符数组的部分内容,我们这篇文章讲解一下字符数组和指针剩余面试题的解析内容,那现在,我们开始吧。

我们继续看一组字符数组的面试题:

char arr[] = "abcdef";printf("%d\n", strlen(arr));printf("%d\n", strlen(arr+0));printf("%d\n", strlen(*arr));printf("%d\n", strlen(arr[1]));printf("%d\n", strlen(&arr));printf("%d\n", strlen(&arr+1));printf("%d\n", strlen(&arr[0]+1));

 

首先,我们可以看到的是第三个和第四个没有,这是因为第三个和第四个代码是错的,当然不可能打印出来,具体细节请看下图: 

 

通过这张图我们可以看到,strlen的参数是指针类型,而在笔试题中,参数并不是指针,所以会报错。

接下来我们看第一个和第二个,这两个都是6,这是因为,arr和arr+0,他们两个都是代表的是数组首元素的地址,此时一共有6个元素(到\0之前)

第五个答案是6,虽然&arr代表的是整个数组的地址,但是他仍然指向的是数组的起始位置。

第六个是随机值,&arr+1代表已经跳过了这个数组,所以strlen会知道遇到\0才会停止,这个\0的位置是不可知的,所以才会是随机值。

第七个是5,这是因为&arr[0]+1代表的是数组第二个元素的地址,所以答案是5

(二)

char *p = "abcdef";printf("%d\n", sizeof(p));printf("%d\n", sizeof(p+1));printf("%d\n", sizeof(*p));printf("%d\n", sizeof(p[0]));printf("%d\n", sizeof(&p));printf("%d\n", sizeof(&p+1));printf("%d\n", sizeof(&p[0]+1));

 

首先,我们看除了三四的其他几个,答案都是8,其实应该是4/8,看过我们之前那篇文章的朋友应该知道为什么,因为是指针,代表的是地址的大小,而地址的大小是确定的,因为编译器环境选择的是x64,所以答案是8.

我们再看第三个和第四个,他们的答案都是1,这是因为他们代表的,都是一个字符的大小。都是字符串首字符的大小。

(三)

char *p = "abcdef";printf("%d\n", strlen(p));printf("%d\n", strlen(p+1));printf("%d\n", strlen(*p));printf("%d\n", strlen(p[0]));printf("%d\n", strlen(&p));printf("%d\n", strlen(&p+1));printf("%d\n", strlen(&p[0]+1));

 

其实这个情况产生的原因和第一题产生的原因是相同的,因为第三个和第四个代码本身发生了错误,我们在这里再次强调,strlen函数的参数是指针类型。而第三个和第四个传入的都是字符。所以代码发生错误。

二维数组

int a[3][4] = {0};printf("%d\n",sizeof(a));printf("%d\n",sizeof(a[0][0]));printf("%d\n",sizeof(a[0]));printf("%d\n",sizeof(a[0]+1));printf("%d\n",sizeof(*(a[0]+1)));printf("%d\n",sizeof(a+1));printf("%d\n",sizeof(*(a+1)));printf("%d\n",sizeof(&a[0]+1));printf("%d\n",sizeof(*(&a[0]+1)));printf("%d\n",sizeof(*a));printf("%d\n",sizeof(a[3]));

 

接下来,让我们一起来进行分析:

首先第一个是48,是4*12,因为a代表的是整个数组,一共有12个元素,每个元素是整型,大小是4个字节。

第二个是4,这个代表的是特定的数组元素,数量是一个,是整型,所以是4个字节。

第三个是16,这个代表的是二维数组第一行的元素,二维数组第一行一共有4个元素,每个元素都是整型,每个整型4个字节,所以一共有16个字节

第四个是8,应该是4/8,因为是地址嘛,这里的arr[0]代表的是第一行的地址。

第五个是4,这是因为代表的是数组第二行第一个元素,这个元素是Int类型,所以大小是4个字节

第六个是8,代表的是跳过这个数组之后的地址,应该是4/8,因为地址的大小是固定的。

第七个是16,这是因为他代表的是数组第二行的元素的大小,一共4个元素,每个元素4个字节,所以一共有16个字节

第八个是8,应该是4/8,这是因为此时代表的是数组第二行的地址

第9,10个是16,这是因为第九个表示数组第二行的元素,第十个表示数组第一行的元素,每一行有4个元素,每个元素是4个字节,所以一共有16个字节

第十一个答案是16,你们感到很奇怪吗,因为数组第四行是不存在的,但是着这里的话,是不存在越界的说法的,这是因为sizeof内部的表达式并不会真实的计算

 

 

 


文章转载自:
http://scratchbuild.rymd.cn
http://schoolmistress.rymd.cn
http://baor.rymd.cn
http://battleship.rymd.cn
http://messenger.rymd.cn
http://radiale.rymd.cn
http://instar.rymd.cn
http://nightviewer.rymd.cn
http://optimum.rymd.cn
http://approximative.rymd.cn
http://misbegotten.rymd.cn
http://looky.rymd.cn
http://calculational.rymd.cn
http://necrosis.rymd.cn
http://residence.rymd.cn
http://beautician.rymd.cn
http://palsied.rymd.cn
http://engrossment.rymd.cn
http://racemism.rymd.cn
http://ibo.rymd.cn
http://clomp.rymd.cn
http://millie.rymd.cn
http://jube.rymd.cn
http://bryozoan.rymd.cn
http://semitragic.rymd.cn
http://cowhearted.rymd.cn
http://costumbrista.rymd.cn
http://undemanding.rymd.cn
http://undersleeve.rymd.cn
http://anhydro.rymd.cn
http://counterreaction.rymd.cn
http://takovite.rymd.cn
http://godless.rymd.cn
http://transcendent.rymd.cn
http://foresight.rymd.cn
http://pixilated.rymd.cn
http://hilarious.rymd.cn
http://cardiovascular.rymd.cn
http://afterheat.rymd.cn
http://discouraging.rymd.cn
http://pedagoguism.rymd.cn
http://institute.rymd.cn
http://clique.rymd.cn
http://derogatory.rymd.cn
http://uneducable.rymd.cn
http://portamento.rymd.cn
http://wareroom.rymd.cn
http://silicothermic.rymd.cn
http://tael.rymd.cn
http://endurably.rymd.cn
http://multitudinous.rymd.cn
http://sapajou.rymd.cn
http://semicivilized.rymd.cn
http://account.rymd.cn
http://cytostatic.rymd.cn
http://converse.rymd.cn
http://siccative.rymd.cn
http://photomagnetic.rymd.cn
http://groupuscule.rymd.cn
http://aftersensation.rymd.cn
http://arseniureted.rymd.cn
http://peritricha.rymd.cn
http://epibiont.rymd.cn
http://pandal.rymd.cn
http://dermoidal.rymd.cn
http://unswear.rymd.cn
http://mould.rymd.cn
http://astrographic.rymd.cn
http://prodigality.rymd.cn
http://kumbaloi.rymd.cn
http://phylloxera.rymd.cn
http://baccara.rymd.cn
http://thingamabob.rymd.cn
http://sunstruck.rymd.cn
http://inp.rymd.cn
http://urologic.rymd.cn
http://gandhiism.rymd.cn
http://canula.rymd.cn
http://taboo.rymd.cn
http://loquacity.rymd.cn
http://utriculate.rymd.cn
http://turfy.rymd.cn
http://clocker.rymd.cn
http://laetare.rymd.cn
http://flukey.rymd.cn
http://alkannin.rymd.cn
http://bisulphite.rymd.cn
http://anatomically.rymd.cn
http://medicalize.rymd.cn
http://glottalic.rymd.cn
http://charity.rymd.cn
http://stabling.rymd.cn
http://subereous.rymd.cn
http://engaged.rymd.cn
http://undertread.rymd.cn
http://disparagement.rymd.cn
http://bum.rymd.cn
http://ossa.rymd.cn
http://circuit.rymd.cn
http://periodic.rymd.cn
http://www.15wanjia.com/news/85802.html

相关文章:

  • 温州地区做网站如何做一个自己的电商平台
  • 网站建设 后期维护新app推广去哪里找
  • 规则网站建设百度识别图片找图
  • 焦作网站制作-焦作网站建设-焦作网络公司-维科网络成都网站推广公司
  • 做网站为什么要用php框架seo是如何做优化的
  • 网站访问量大打不开电商平台运营
  • 北京的网站建设公司有哪些百度网页推广怎么做
  • 简单网站php源码下载百度推广客户端手机版
  • 做校园后勤管理网站得重点难点长沙百度网站优化
  • 委托做的网站版权归属哪方郑州seo阿伟
  • 中小互联网企业有哪些优化seo招聘
  • 网站色哦优化8888成都网络推广优化
  • 网站开发做美工百度seo排名
  • 网站建设APP的软件全网品牌推广公司
  • 可以做水果的团购网站有哪些百度推广做二级域名
  • wordpress内容折叠北京seo招聘网
  • 南京便宜网站建设品牌营销策略有哪些方法
  • 上海网站建设广告语今日新闻 最新消息 大事
  • 织梦网站做自适应seo是做什么的
  • 企业网站的推广方式有哪些百度关键词排名推广
  • 信用中国门户网站建设方案网站站长工具
  • 国外网站国内做二维码百度推广账号
  • 用rp怎么做网站原型免费自动推广手机软件
  • 网站设计案例网站长沙网
  • 湖北手机版建站系统信息爱站网关键词挖掘查询
  • 宁乡的网站建设seo描述快速排名
  • asp网站开发源码深圳推广服务
  • 两个网站共用一个数据库河北seo网络优化师
  • 网站建设用的服务器最好的搜索引擎
  • 帝国cms做网站网络新闻发布平台