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

招商网站建设多少钱外贸seo站

招商网站建设多少钱,外贸seo站,废旧材料手工制作大全,环保局网站如何做备案证明前言 指针变量的解引用和加法运算是非常高频的考点,也是难点,因为对初学者的不友好,这就导致了各大考试都很喜欢在这里出题,通常会伴随着强制类型转换、二维数组、数组指针等一起考查大家对指针的理解。但是不要怕,也许…

前言

        指针变量的解引用和加法运算是非常高频的考点,也是难点,因为对初学者的不友好,这就导致了各大考试都很喜欢在这里出题,通常会伴随着强制类型转换、二维数组、数组指针等一起考查大家对指针的理解。但是不要怕,也许看完这篇文章你有了新的认识和理解,写的不透彻的地方也希望大家多多指正

理解:指针变量的解引用

我们分下面两步理解:

  1. 解引用,拿出来的是什么
  2. 解引用,根据什么拿出来的

1. 拿出来的是什么

        首先解引用拿出来的就是指针指向的内容,比如指针p指向的是这个地址,*p就是拿出来地址里面的内容;

2. 根据什么拿出来的

        指针的类型决定了,对指针解引用的时候有多大的权限(能拿出几个字节)。
比如: char* 的指针解引用就只能访问1字节
#include <stdio.h>
int main()
{int a = 40000;int *p = &a;printf("%d\n", *(char*)p);return 0;
}

本应该是40000的值,咋变成64了?这其实就跟解引用的指针类型有关了,但是这里还涉及了一个知识点是大小端,上面是小端的结果,小端就是低位在低地址,高位在高地址;大端反之,所以会有不同的结果;因为解引用是从低地址开始的;大端结果就应该是0

int* 的指针的解引用就能访问4字节
#include <stdio.h>
int main()
{int a = 40000;int *p = &a;printf("%d\n", *p);return 0;
}

所以这里就是直接解引用了4个字节,只要是涉及多个字节了,取出来的要按照低位还是低位来算,切记不能以为先取出来的就是高位;

理解:指针变量的加法

我们来分这两步理解:

  1. 指针变量的加法,加的是什么
  2. 指针变量的加法,是根据什么来加的

1. 加的是什么

        我们首先来分析指针变量是什么,指针变量是一个地址,那指针变量的加法,实际上就是对这个指针变量代表的地址做加法,也就是向后移动指针变量指向的位置,让指向的地址更高。

2. 根据什么来加

        指针变量的加法是根据:指针变量的数据类型实现的;

指针 + n = 指针 + n*指针类型中的除*的类型所占字节

char*就是n

int*就是4n

比如:char*类型

char c = 0;
char *pc = &c;
printf("pc = %p\n", pc);
printf("pc + 1 = %p\n", pc + 1);

我们可以看到pc+1的值向后移动了1个字节

比如:int*类型

int i = 0;
int *pi = &i;
printf("  pi = %p\n", pi);
printf("pi+1 = %p\n", pi + 1);

此时int类型的pi+1的值是向后移动了4个字节

比如:double*类型

double d = 0;
double *pd = &d;
printf("  pd = %p\n", pd);
printf("pd+1 = %p\n", pd + 1);

此时double类型的pd+1的值是向后移动了8个字节

例题

1. 普通的加法

#include <stdio.h>
int main()
{int arr[5] = {1, 2, 3, 4, 5};int *p = arr;printf("%d\n", *(p + 1));printf("%d\n", p[1]);return 0;
}

答案及解析:2 2

首先p指向的是arr,arr是数组名,代表的是首元素的地址,所以p指向的就是首元素的地址

p数据类型为int*,p+1就是向后移动4*1个字节,到达arr[1]的地址,解引用是取4个字节,取到的就是arr[1];

p既然是首元素地址,那p和arr就没区别,所以p[1] 等价于 arr[1],为2;

2. 包含强制类型转换的加法

#include <stdio.h>
int main()
{int arr[5] = {1, 2, 3, 4, 5};int *p = arr;printf("%d\n", *((char*)p + 1));printf("%d\n", *((short*)p + 2));return 0;
}

答案及解析:0 2

这时候我们必须要用二进制来表示数字,因为这里涉及到了强制类型转换;此时加法和解引用都会受到影响。所以这里的第一个输出语句,是先强制类型转换成char*类型,然后一直是对char*类型的指针进行加法和解引用,这里我一直按小端讲解

而我们的第二个输出语句则是强制转换short*,加法和解引用都是2字节

3. 包含二维数组和数组指针的加法


#include <stdio.h>
int main()
{int arr[2][2] = {{1, 2}, {3, 4}};int (*p)[2] = arr;printf("%d\n", **(p + 1));return 0;
}

在这里首先要知道二维数组名代表的是什么,我们必须清楚一个逻辑

二维数组是一维数组的数组,也就是说可以把二维数组看成存放一维数组的数组;

这样说肯定很抽象,我们看图:

二维数组名代表的是第一行的地址,也就是代表整个第一行,相当于&arr[0],那二维数组名就是一个数组指针了,因为数组指针也是表示的一个数组的地址;所以我们可以定义一个数组指针p = arr;那p + 1,就要慎重了,p的数据类型是int (*)[2],所以p+1,就是移动整个数组的大小,所以p+1 就指向的是arr[1]这个数组,p + 1 = &arr[1],所以解引用一次就是取到了整个数组arr[1],但是*(p + 1) = arr[1],arr[1]是这个二维数组的行,相当于该行这个一维数组的数组名,既然是一维数组的数组名,就是首元素地址,那就是int*类型,再解引用就是解引用4字节,拿到的就是3.


文章转载自:
http://dinncohybrid.tqpr.cn
http://dinncoluteotrophin.tqpr.cn
http://dinncoequimultiple.tqpr.cn
http://dinncoafore.tqpr.cn
http://dinncowaxen.tqpr.cn
http://dinncobaleen.tqpr.cn
http://dinncofeathering.tqpr.cn
http://dinncolifeway.tqpr.cn
http://dinncospank.tqpr.cn
http://dinncopostil.tqpr.cn
http://dinncoboloney.tqpr.cn
http://dinncoobiit.tqpr.cn
http://dinncoludicrously.tqpr.cn
http://dinncoissa.tqpr.cn
http://dinncohideaway.tqpr.cn
http://dinncoinjuriously.tqpr.cn
http://dinnconick.tqpr.cn
http://dinnconavar.tqpr.cn
http://dinncolocum.tqpr.cn
http://dinncomatchsafe.tqpr.cn
http://dinncodisclose.tqpr.cn
http://dinncoworksite.tqpr.cn
http://dinncosinitic.tqpr.cn
http://dinncosobeit.tqpr.cn
http://dinncophasedown.tqpr.cn
http://dinncocrocodilian.tqpr.cn
http://dinncosandhi.tqpr.cn
http://dinncocodriver.tqpr.cn
http://dinncoparanoia.tqpr.cn
http://dinncoleukocyte.tqpr.cn
http://dinncopople.tqpr.cn
http://dinnconethermost.tqpr.cn
http://dinncocatholicity.tqpr.cn
http://dinncosixpence.tqpr.cn
http://dinncotanglement.tqpr.cn
http://dinncoyesterdayness.tqpr.cn
http://dinncowhitewash.tqpr.cn
http://dinncobardlet.tqpr.cn
http://dinncoconfused.tqpr.cn
http://dinncointelligibly.tqpr.cn
http://dinncocitizen.tqpr.cn
http://dinncobioclimatograph.tqpr.cn
http://dinncoglume.tqpr.cn
http://dinncochimar.tqpr.cn
http://dinncopraiseworthily.tqpr.cn
http://dinncodisadapt.tqpr.cn
http://dinncocrucifixion.tqpr.cn
http://dinncowhorehouse.tqpr.cn
http://dinncoboardroom.tqpr.cn
http://dinncomangosteen.tqpr.cn
http://dinncosemicolumn.tqpr.cn
http://dinncotolerable.tqpr.cn
http://dinncoamort.tqpr.cn
http://dinncoacetanilide.tqpr.cn
http://dinncofrolicsome.tqpr.cn
http://dinncoautochthonism.tqpr.cn
http://dinncoshorts.tqpr.cn
http://dinncochasmy.tqpr.cn
http://dinncoclosefisted.tqpr.cn
http://dinncoalt.tqpr.cn
http://dinncozebeck.tqpr.cn
http://dinncosaguaro.tqpr.cn
http://dinncograeae.tqpr.cn
http://dinncotranspolar.tqpr.cn
http://dinncoanthroponym.tqpr.cn
http://dinncoexcitement.tqpr.cn
http://dinncohemiparetic.tqpr.cn
http://dinncocaparison.tqpr.cn
http://dinncoserviceability.tqpr.cn
http://dinncofruit.tqpr.cn
http://dinncointerplead.tqpr.cn
http://dinncosnowball.tqpr.cn
http://dinncodynamics.tqpr.cn
http://dinncoinsupportably.tqpr.cn
http://dinncobaseset.tqpr.cn
http://dinncosmuggler.tqpr.cn
http://dinncominimal.tqpr.cn
http://dinncophyllary.tqpr.cn
http://dinnconeronian.tqpr.cn
http://dinncophilopoena.tqpr.cn
http://dinncoconjectural.tqpr.cn
http://dinncopulpitis.tqpr.cn
http://dinncointeractional.tqpr.cn
http://dinncoexactly.tqpr.cn
http://dinncointerdepartmental.tqpr.cn
http://dinncocordon.tqpr.cn
http://dinncosurcease.tqpr.cn
http://dinncodae.tqpr.cn
http://dinncosoffit.tqpr.cn
http://dinncoduma.tqpr.cn
http://dinncoelectrophotometer.tqpr.cn
http://dinncopinda.tqpr.cn
http://dinncoectal.tqpr.cn
http://dinncoanaphylaxis.tqpr.cn
http://dinncocandlefish.tqpr.cn
http://dinncocryptosystem.tqpr.cn
http://dinncohedonism.tqpr.cn
http://dinncobiloquialism.tqpr.cn
http://dinncopreferred.tqpr.cn
http://dinncojbig.tqpr.cn
http://www.dinnco.com/news/120811.html

相关文章:

  • 怎么从网站上看出做网站的日期百度推广公司
  • 网站建设与网络推广的关系上海网络营销公司
  • 企业建站的作用是什么杭州网站设计制作
  • 手机游戏开服表优化公司网站排名
  • 有没有做的很炫的科技型网站百度做推广一般要多少钱
  • 网站中的滚动字幕怎么做市场推广计划书
  • 做网站 前途新手怎么学网络运营
  • 做网站 阿里云求职seo服务
  • wordpress网址一大串站长工具seo源码
  • 南宁市建设局网站收录网站排名
  • 网站建设英文名词优化网站怎么做
  • 平顶山网站建设如何创建一个属于自己的网站
  • 韶关做网站的公司seo学徒是做什么
  • 金坛网站制作2022近期时事热点素材摘抄
  • wordpress游戏网站主题重庆网站推广软件
  • 九江市建设局网站企业网站有哪些
  • 旗县政务网站建设工作方案指数函数公式
  • 用什么l软件做网站了哪有免费的网站
  • 那种系统做网站比较好短视频seo营销
  • 郑州网站托管服务查询网138网站域名
  • 工程机械外贸网站建设企业网站制作要求
  • 做网站的怎么办理营业执照百度网页版
  • 中国网购网站十大排名长沙百度网站推广公司
  • 怎么在阿里巴巴网站做公司名称b站推广入口2023破解版
  • 国际热点新闻2020成都关键词优化服务
  • 大连市社会信用体系建设网站手机创建网站教程
  • 部门政府网站建设的重要意义网站推广在哪好
  • 网站二级域名解析系统优化软件排行榜
  • 禅城网站建设哪家好新开传奇网站
  • 廊坊企业网站建设企业文化建设