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

网站布局方法全网品牌推广公司

网站布局方法,全网品牌推广公司,装修公司设计图,视频网站用户增长怎么做指针和数组我们已经学习的差不多了,今天就为大家分享一些指针和数组的常见练习题,还包含许多经典面试题哦! 一、求数组长度和大小 普通一维数组 int main() {//一维数组int a[] { 1,2,3,4 };printf("%d\n", sizeof(a));//整个数组…

指针和数组我们已经学习的差不多了,今天就为大家分享一些指针和数组的常见练习题,还包含许多经典面试题哦!


一、求数组长度和大小

普通一维数组

int main()
{//一维数组int a[] = { 1,2,3,4 };printf("%d\n", sizeof(a));//整个数组大小16printf("%d\n", sizeof(a + 0));//首元素地址8printf("%d\n", sizeof(*a));//首元素4printf("%d\n", sizeof(a + 1));//第二个元素地址8printf("%d\n", sizeof(a[1]));//第二个元素4printf("%d\n", sizeof(&a));//整个数组地址 8printf("%d\n", sizeof(*&a));//先拿到这个数组地址,再解引用拿到整个数组(即:数组名)-》16printf("%d\n", sizeof(&a + 1));//地址8printf("%d\n", sizeof(&a[0]));//第一个元素地址8printf("%d\n", sizeof(&a[0] + 1));//第二个元素地址8return 0;
}

字符数组

int main()
{//字符数组char arr[] = { 'a','b','c','d','e','f' };printf("%d\n", sizeof(arr));//整个数组 6printf("%d\n", sizeof(arr + 0));//数组首元素地址8printf("%d\n", sizeof(*arr));//第一个元素1printf("%d\n", sizeof(arr[1]));//第一个元素1printf("%d\n", sizeof(&arr));//整个数组地址8printf("%d\n", sizeof(&arr + 1));//地址8printf("%d\n", sizeof(&arr[0] + 1));//第二个元素地址8printf("%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((const char*) & arr));printf("%d\n", strlen((const char*)(&arr + 1)));printf("%d\n", strlen(&arr[0] + 1));//随机值return 0;
}

字符串数组

int main()
{char arr[] = "abcdef";printf("%d\n", sizeof(arr));//这个数组7printf("%d\n", sizeof(arr + 0));//第一个元素地址8printf("%d\n", sizeof(*arr));//第一个元素1printf("%d\n", sizeof(arr[1]));//第一个元素1printf("%d\n", sizeof(&arr));//这个数组地址8printf("%d\n", sizeof(&arr + 1));//地址8printf("%d\n", sizeof(&arr[0] + 1));//第二个元素地址8printf("%d\n", strlen(arr));//数组长度6printf("%d\n", strlen(arr + 0));//6/*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));//5return 0;
}

指向字符串的字符指针

int main()
{const char* p = "abcdef";printf("%d\n", sizeof(p));//指针,大小8printf("%d\n", sizeof(p + 1));//指针,大小8printf("%d\n", sizeof(*p));//第一个字符a,大小1printf("%d\n", sizeof(p[0]));//第一个字符a,大小1printf("%d\n", sizeof(&p));//指针的地址,大小8printf("%d\n", sizeof(&p + 1));//指针的地址,大小8printf("%d\n", sizeof(&p[0] + 1));//第二个元素地址,大小8printf("%d\n", strlen(p));//长度,6printf("%d\n", strlen(p + 1));//长度,5/*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));//长度,5return 0;
}

二维数组

//int main()
//{
//	int a[3][4] = { 0 };
//	printf("%d\n", sizeof(a));//整个数组大小,48
//	printf("%d\n", sizeof(a[0][0]));第一个元素,大小4//	printf("%d\n", sizeof(a[0]));//第一行数组的数组名,大小16
// a[0]是第一行一维数组的数组名,数组名单独放在了sizeof里面,就表示整个数组,所以就算的就算整个数组的大小 为16//	printf("%d\n", sizeof(a[0] + 1));//第一行第二个元素地址,8
//	printf("%d\n", sizeof(*(a[0] + 1)));//第一行第二个元素,大小4
//	printf("%d\n", sizeof(a + 1));//第二行的地址,大小8
//	printf("%d\n", sizeof(*(a + 1)));//第二行数组的数组名,大小16
//	printf("%d\n", sizeof(&a[0] + 1));//第二行数组地址,大小8
//	printf("%d\n", sizeof(*(&a[0] + 1)));//第二行数组数组名,大小16
//	printf("%d\n", sizeof(*a));//第一行数组数组名,大小16
//	printf("%d\n", sizeof(a[3]));//数组名,大小16
//
//	return 0;
//}/*
二维数组有的情况下可以拿到某一行数组的数组名,这时放在sizeof中就算的也是那行数组的大小
二维数组就是数组的数组,,就是一维数组的数组
eg:
a[3][4]    a[0]就是第一行数组的数组名,sizeof算他的大小为第一行整个数组的大小   为:16
*/

总节:

数组名的意义:

  1. sizeof(数组名),这里的数组名表示整个数组,计算的是整个数组的大小。
  2. &数组名,这里的数组名表示整个数组,取出的是整个数组的地址。
  3. 除此之外所有的数组名都表示首元素的地址。

二、指针相关题型

笔试题1:

int main()
{int a[5] = { 1, 2, 3, 4, 5 };int* ptr = (int*)(&a + 1);printf("%d,%d", *(a + 1), *(ptr - 1));//2   5return 0;//程序的结果是什么?return 0;
}

在这里插入图片描述

笔试题2:

struct Test
{int Num;char* pcName;short sDate;char cha[2];short sBa[4];
}*p;
//假设p 的值为0x100000。 如下表表达式的值分别为多少?
//已知,结构体Test类型的变量大小是20个字节
int main()
{p = (struct Test*)0x100000;printf("%p\n", p + 0x1);//0x100014printf("%p\n", (unsigned long)p + 0x1);//0x100001printf("%p\n", (unsigned int*)p + 0x1);//0x100004return 0;
}

分析:

  1. p为结构体指针,+1相当于跳过一个结构体大小,这里告知结构体的大小是20个字节,p + 0x1按16进制打印出来是0x100014
  2. p转化为无符号 长整型,并非指针,+1,就是+1,0x100001
  3. p转化为无符号整型类型指针+1跳过四个字节。0x100004
    由于以%p打印,第一个00100014,第二个00100001,第三个00100004

笔试题3:

int main()
{int a[4] = { 1, 2, 3, 4 };int* ptr1 = (int*)(&a + 1);int* ptr2 = (int*)((int)a + 1);printf("%x,%x", ptr1[-1], *ptr2);//4   2000000//%x打印16进制//%o打印8进制return 0;
}

在这里插入图片描述

笔试题4:

int main()
{int a[3][2] = { (0, 1), (2, 3), (4, 5) };int* p;p = a[0];//p就算第一个元素地址printf("%d", p[0]);//return 0;
}

在这里插入图片描述

笔试题5:

int main()
{int a[5][5];int(*p)[4];p = (int(*)[4]) a;printf("%p,%d\n", &p[4][2] - &a[4][2], &p[4][2] - &a[4][2]);return 0;
}

在这里插入图片描述
所以相减就是-4
在这里插入图片描述

笔试题6:

//int main()
//{
//	int aa[2][5] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//	int* ptr1 = (int*)(&aa + 1);
//	int* ptr2 = (int*)(*(aa + 1));
//	printf("%d,%d", *(ptr1 - 1), *(ptr2 - 1));//10 5
//	return 0;
//}

在这里插入图片描述

笔试题7:

int main()
{const char* a[] = { "work","at","alibaba" };const char** pa = a;pa++;printf("%s\n", *pa);//       atreturn 0;
}

这是其中的关系的分布图:
在这里插入图片描述

笔试题8:

int main()
{const char* c[] = { "ENTER","NEW","POINT","FIRST" };const char** cp[] = { c + 3,c + 2,c + 1,c };const char*** cpp = cp;printf("%s\n", **++cpp);//POINTprintf("%s\n", *-- * ++cpp + 3);//ERprintf("%s\n", *cpp[-2] + 3);//STprintf("%s\n", cpp[-1][-1] + 1);//EWreturn 0;
}

在这里插入图片描述
1、++cpp,cpp指向c+2,解引用拿到c+2,在解引用拿到POINT的首地址,然后按照%s打印出来POINT
2、++cpp,使cpp指向c+1,解引用拿到c+1,再–(c+1)使其指向c,再解引用拿到ENTER的地址,再+3拿到E的地址,根据%s打印出ER
类方法就是这样子,依次可以全部解出来

总结:
今天的指针数组练习题就分享到这里啦,这些题型都能够很好的帮助我们对数组和指针有更加深刻的掌握,谢谢大家!!!


文章转载自:
http://dinncocacm.tpps.cn
http://dinncostuggy.tpps.cn
http://dinncofelted.tpps.cn
http://dinncorowdedowdy.tpps.cn
http://dinncobgp.tpps.cn
http://dinncovlan.tpps.cn
http://dinncoaround.tpps.cn
http://dinncodiverticulum.tpps.cn
http://dinncocreamy.tpps.cn
http://dinncotempestuousness.tpps.cn
http://dinncocoxswain.tpps.cn
http://dinncoresorption.tpps.cn
http://dinncounskillful.tpps.cn
http://dinncoseptavalent.tpps.cn
http://dinncofree.tpps.cn
http://dinncodysteleological.tpps.cn
http://dinncocontredanse.tpps.cn
http://dinncoremigrant.tpps.cn
http://dinncopertussis.tpps.cn
http://dinncodiscussant.tpps.cn
http://dinncocrinkle.tpps.cn
http://dinncopebbly.tpps.cn
http://dinncowashed.tpps.cn
http://dinncoinheritrix.tpps.cn
http://dinncosunwards.tpps.cn
http://dinncoaardwolf.tpps.cn
http://dinncoapivorous.tpps.cn
http://dinncokentish.tpps.cn
http://dinncopyxides.tpps.cn
http://dinncoacclimate.tpps.cn
http://dinncosurveying.tpps.cn
http://dinncoheterograft.tpps.cn
http://dinncoirredentist.tpps.cn
http://dinncokarakalpak.tpps.cn
http://dinncophon.tpps.cn
http://dinncomerozoite.tpps.cn
http://dinncointerstratify.tpps.cn
http://dinncoevaluation.tpps.cn
http://dinncoweatherboard.tpps.cn
http://dinncolockean.tpps.cn
http://dinncounderdevelop.tpps.cn
http://dinncoczaritza.tpps.cn
http://dinncosemihuman.tpps.cn
http://dinncoinductivism.tpps.cn
http://dinncoarchdeacon.tpps.cn
http://dinncoundefined.tpps.cn
http://dinncofisk.tpps.cn
http://dinncoscholium.tpps.cn
http://dinncopinecone.tpps.cn
http://dinncodiallage.tpps.cn
http://dinncomyricin.tpps.cn
http://dinncotimeserver.tpps.cn
http://dinncobaltimore.tpps.cn
http://dinncoslapman.tpps.cn
http://dinncogeorgie.tpps.cn
http://dinncolucifugous.tpps.cn
http://dinncosquirm.tpps.cn
http://dinncoacusector.tpps.cn
http://dinncojesuit.tpps.cn
http://dinncoleucomaine.tpps.cn
http://dinncoalphametic.tpps.cn
http://dinncoiterate.tpps.cn
http://dinncopolyacrylamide.tpps.cn
http://dinncomarcella.tpps.cn
http://dinncointeractional.tpps.cn
http://dinncointerconnect.tpps.cn
http://dinncoshelton.tpps.cn
http://dinncoessence.tpps.cn
http://dinncoforepole.tpps.cn
http://dinncoparmesan.tpps.cn
http://dinncoconcomitance.tpps.cn
http://dinncochronology.tpps.cn
http://dinncoquerist.tpps.cn
http://dinncointroducer.tpps.cn
http://dinncoessen.tpps.cn
http://dinncoanticlerical.tpps.cn
http://dinncostalagmite.tpps.cn
http://dinncojaques.tpps.cn
http://dinncointroversion.tpps.cn
http://dinncomohammed.tpps.cn
http://dinnconicaragua.tpps.cn
http://dinncogalenical.tpps.cn
http://dinncotopcoat.tpps.cn
http://dinncotackling.tpps.cn
http://dinncosolvable.tpps.cn
http://dinncoendemicity.tpps.cn
http://dinncoantibaryon.tpps.cn
http://dinncoenduro.tpps.cn
http://dinncoshasta.tpps.cn
http://dinncoproportion.tpps.cn
http://dinncoseism.tpps.cn
http://dinncosubdued.tpps.cn
http://dinncoresid.tpps.cn
http://dinncoseaquake.tpps.cn
http://dinncomercapto.tpps.cn
http://dinncomascaret.tpps.cn
http://dinncoheptachord.tpps.cn
http://dinncoatomise.tpps.cn
http://dinncoembonpoint.tpps.cn
http://dinncoseptemviral.tpps.cn
http://www.dinnco.com/news/129024.html

相关文章:

  • 鲜花网站建设源代码品牌整合营销方案
  • 电子商务网站建设应用关键词优化搜索排名
  • 网站搜索下拉是怎么做的怎样做竞价推广
  • 35互联做网站好吗seo优化公司信
  • 做律师百度推广的网站网站推广去哪家比较好
  • 十种网络营销的方法合肥seo快排扣费
  • node.js做的网站广州seo推广公司
  • 阿里云盘资源搜索引擎郑州seo技术外包
  • 网站开发案例分析中视频自媒体平台注册
  • 单页网站制作程序模板建网站价格
  • 婺源做网站南宁seo结算
  • 涪城移动网站建设网页设计网站
  • 建网站流程游戏广告投放平台
  • 嘉兴模板建站系统公关公司经营范围
  • 网站备案 名称 不一致有什么引流客源的软件
  • 免费的企业网站建设流程百度站长工具排名
  • 做买衣服的网站免费手机优化大师下载安装
  • 做代理哪个网站靠谱优化大师平台
  • 汕头网站备案网上售卖平台有哪些
  • 北京的重要的网站小熊猫seo博客
  • ui设计30岁后的出路seo关键字排名
  • 做百度网站优化多少钱官网seo关键词排名系统
  • wordpress 小说网站seo优化的搜索排名影响因素主要有
  • 对自己做的网站总结厦门头条今日新闻
  • 网络规划设计师自学能通过么郑州优化网站关键词
  • 苏州注册公司一站式网站生成器
  • 公司网站建设的分类解封后中国死了多少人
  • 运输网站建设宁波网站推广优化哪家正规
  • wordpress浏览器版本seo工具下载
  • 公司介绍网站怎么做aso优化平台