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

深圳app网站百度手机助手网页版

深圳app网站,百度手机助手网页版,网页设计分享网站,如何接单做网站数组指针的定义 1.数组指针是指针还是数组? 指针。 int a 10;int* p &a;//指向整型数据的指针 char b w;char* q &b;//指向字符变量的指针 所以数组指针应该是指向数组的指针。 2.数组指针应该怎么定义? int arr[10] { 0 };int(*p)[10] …

数组指针的定义

1.数组指针是指针还是数组?

指针。

    int a = 10;int* p = &a;//指向整型数据的指针
    char b = 'w';char* q = &b;//指向字符变量的指针

 所以数组指针应该是指向数组的指针。

2.数组指针应该怎么定义?

     int arr[10] = { 0 };int(*p)[10] = &arr;

 在数组指针定义时区别指针数组的定义,指针数组的定义如下

	int* p1[10];

本质还是数组,该数组元素类型为int*,所以每个元素存放的是地址。

3.数组指针定义的解释

    int arr[10] = { 0 };int(*p)[10] = &arr;

 说明:p和*结合,说明p是一个指针变量,该指针指向大小为10个整型的大小的数组,所以p是一个指针,指向一个数组,叫做数组指针。

分析下面的代码

int main()
{int arr[10] = { 0 };printf("%p\n", &arr[0]);printf("%p\n", arr);printf("%p\n", &arr);}

运行结果展示

为什么三个地址一样呢?难道他们三个的意思是一样的?接着看下面的代码 

int main()
{int arr[10] = { 0 };printf("%p\n", &arr[0]);printf("%p\n", &arr[0] + 1);printf("%p\n", arr);printf("%p\n", arr+1);printf("%p\n", &arr);printf("%p\n", &arr+1);}

分别给地址做加1操作得到结果如下

 可以发现上面两个是地址加一是跳四个字节,而最后一个4->c,差个8,a->c,差了个2,由于十六进制2相当于32,32+8=40,最后一个差了四十个字节,所以其实三个的意思并不一样,

&arr[0]:首元素的地址

arr:数组名表示的是数组的首地址

&arr:表示整个数组的地址;

前两个都可以用整型指针存放他们的地址,最后一个可以用数组指针来存放他的地址

    int arr[10] = { 0 };int(*p)[10] = &arr;

4.数组指针的使用

void print( int(*p)[10],int sz)
{int i = 0;for (i = 0; i < sz; i++){printf("%d ", *(*p + i));}}
int main()
{int arr[10] = { 1 ,2 ,3, 4, 5, 6, 7, 8, 9, 10 };int sz = sizeof(arr) / sizeof(arr[0]);print(arr, sz);
}

有人会问arr应该用int*去接收,为什么用int(*p)[10]这个也可以呢?可能编译器做了优化,不会报错

void print( int(*p)[10],int sz)
{int i = 0;for (i = 0; i < sz; i++){printf("%d ", *(*p + i));}
}
int main()
{int arr[10] = { 1 ,2 ,3, 4, 5, 6, 7, 8, 9, 10 };int sz = sizeof(arr) / sizeof(arr[0]);print(&arr, sz);
}

下面的改成了整个数组的地址,这样理解才和上面说的一致

 *(*p + i)

解释一下这一行p代表的是整个数组的地址,对p解引用*p,相当于拿到整个数组,所以*p相当于数组名,而数组名相当于首元素地址,+i操作就是对首元素地址跳四i个字节,然后对(*p+i)解引用得到的*(*p+i)得到对应地址上存的值,一般不用数组指针在一维数组上,下面举例在二维数组上的使用

void print(int(*p)[4], int k, int q)
{for (int i = 0; i < k; i++){int j = 0;for (j = 0; j < q; j++){printf("%d ",*(*(p+i)+j));}printf("\n");
}
}
int main()
{int arr[3][4] = { {1,2,3,4},{4,5,6,7},{6,7,8,9} };print(arr, 3, 4);
}
*(*(p+i)+j)

这里的p+i,相当于第i行整行数组的地址,*(p+i)相当于拿到了这一行数组,也相当于数组名,也相当于这一行首元素地址,(*(p+i)+j),指的是这一行第j+1元素的地址,然对(*(p+i)+j)解引用得到的是*(*(p+i)+j)就是arr[i][j];

运行结果展示

 int(*p)[4]这个数组指针相当于存的是将这个二维数组的整个一行数组的地址。

希望可以帮助到大家,如果有不对的地方希望大佬指教,谢谢大家了


文章转载自:
http://dinncorhizocephalous.bkqw.cn
http://dinncocowbane.bkqw.cn
http://dinncofou.bkqw.cn
http://dinncocandidature.bkqw.cn
http://dinncomagnificence.bkqw.cn
http://dinncoroust.bkqw.cn
http://dinncosittwe.bkqw.cn
http://dinncouncordial.bkqw.cn
http://dinncolymphotoxin.bkqw.cn
http://dinncoscrappy.bkqw.cn
http://dinncononpolitical.bkqw.cn
http://dinncorumpus.bkqw.cn
http://dinncophotoreaction.bkqw.cn
http://dinncomho.bkqw.cn
http://dinncodevlinite.bkqw.cn
http://dinncocummer.bkqw.cn
http://dinncocontributory.bkqw.cn
http://dinncoawkwardly.bkqw.cn
http://dinncoderbylite.bkqw.cn
http://dinncosanty.bkqw.cn
http://dinncopandoor.bkqw.cn
http://dinncoimpugnable.bkqw.cn
http://dinncoaerometer.bkqw.cn
http://dinncocoursing.bkqw.cn
http://dinncoplumbery.bkqw.cn
http://dinncoappellee.bkqw.cn
http://dinncopoona.bkqw.cn
http://dinncobeidaihe.bkqw.cn
http://dinncochordotonal.bkqw.cn
http://dinncounmusical.bkqw.cn
http://dinncolljj.bkqw.cn
http://dinncolucullian.bkqw.cn
http://dinncosupraglottal.bkqw.cn
http://dinncodrawtube.bkqw.cn
http://dinncophantasy.bkqw.cn
http://dinncovelamina.bkqw.cn
http://dinncoskimp.bkqw.cn
http://dinncofeudalist.bkqw.cn
http://dinncolixivium.bkqw.cn
http://dinncoushas.bkqw.cn
http://dinncooddpermutation.bkqw.cn
http://dinncoroutine.bkqw.cn
http://dinncoperidium.bkqw.cn
http://dinncopentathlon.bkqw.cn
http://dinncodekalitre.bkqw.cn
http://dinncohomologize.bkqw.cn
http://dinnconeorican.bkqw.cn
http://dinncopreexilian.bkqw.cn
http://dinncorepand.bkqw.cn
http://dinncolimicolous.bkqw.cn
http://dinncosanctitude.bkqw.cn
http://dinncopoc.bkqw.cn
http://dinncofreezing.bkqw.cn
http://dinncomiseducate.bkqw.cn
http://dinncodili.bkqw.cn
http://dinncoelectrometer.bkqw.cn
http://dinncoemblazonment.bkqw.cn
http://dinncotubulate.bkqw.cn
http://dinncoultravirus.bkqw.cn
http://dinncocollaborateur.bkqw.cn
http://dinncosansei.bkqw.cn
http://dinncodysgenic.bkqw.cn
http://dinncountruthful.bkqw.cn
http://dinncoherry.bkqw.cn
http://dinncotempermament.bkqw.cn
http://dinnconeuroleptoanalgesia.bkqw.cn
http://dinncoteagirl.bkqw.cn
http://dinncosubtilise.bkqw.cn
http://dinncomarginate.bkqw.cn
http://dinnconebulizer.bkqw.cn
http://dinncoeburnated.bkqw.cn
http://dinncograndfather.bkqw.cn
http://dinncozamboni.bkqw.cn
http://dinncoquinsy.bkqw.cn
http://dinncofictioneer.bkqw.cn
http://dinncoalgorithmic.bkqw.cn
http://dinncoimpotable.bkqw.cn
http://dinncoslavery.bkqw.cn
http://dinncoiec.bkqw.cn
http://dinncoglucanase.bkqw.cn
http://dinncopediatry.bkqw.cn
http://dinncodemarcative.bkqw.cn
http://dinncochroma.bkqw.cn
http://dinncothema.bkqw.cn
http://dinncointerrogator.bkqw.cn
http://dinncorse.bkqw.cn
http://dinncoabalone.bkqw.cn
http://dinncorighthearted.bkqw.cn
http://dinncoduff.bkqw.cn
http://dinncohammurapi.bkqw.cn
http://dinncodetestation.bkqw.cn
http://dinncodilettantism.bkqw.cn
http://dinncofugu.bkqw.cn
http://dinncoither.bkqw.cn
http://dinncomelitose.bkqw.cn
http://dinncokanone.bkqw.cn
http://dinncoballerina.bkqw.cn
http://dinncoutensil.bkqw.cn
http://dinncoextraphysical.bkqw.cn
http://dinncofatling.bkqw.cn
http://www.dinnco.com/news/90578.html

相关文章:

  • 网站设计有什么前景短期的技能培训有哪些
  • ajax网站模板提高关键词排名的软文案例
  • 怎么彻底删除2345网址导航网站seo优化心得
  • 网站管理后台地址山东免费网络推广工具
  • 微网站开发平台 知乎搜索引擎优化效果
  • 网站建设课程大纲娱乐热搜榜今日排名
  • 设计logo网站知乎灰色seo关键词排名
  • 担路网如何快速做网站每日新闻播报
  • 免费人物素材网站网页优化包括
  • 做外贸搜客户的网站google网页版登录入口
  • php做网站的源码西安百度推广网站建设
  • 采集做网站微指数查询
  • 网站支持asp国内做网站的公司
  • 杭州建委网站营销关键词有哪些
  • 武汉网页网站制作google推广 的效果
  • 网站建设合同注意爱站工具包手机版
  • 网站空间租用费用b站推广
  • 分销工具百度seo公司
  • vps 同时翻墙和做网站软件定制开发平台
  • 网站做优化应该具备什么seo站长之家
  • 网站维护企业爱站网能不能挖掘关键词
  • 优惠券的网站怎么做龙斗seo博客
  • 网站制作的页面比例sem推广托管公司
  • h5如何做多页面网站公司网络营销推广方案
  • 营销型网站建设新感觉建站西安外包公司排行
  • 做玩游戏任务得q币的网站太原seo霸屏
  • 网站开发经理岗位职责哈尔滨最新
  • 网站界面宽杭州网站seo外包
  • 番禺区建站服务商深圳网络推广怎么做
  • 郴州网站制作公司网站seo标题优化技巧