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

网站怎么百度收录百度手机应用市场

网站怎么百度收录,百度手机应用市场,注册开发公司,网页设计基础实训报告目录 1. 字符指针1.1 一般用法:字符指针指向单字符1.2 第二种用法,字符串首地址给指针变量1.3 习题,下面代码的输出结果是什么?为什么? 2. 指针数组2.1实例—— 字符指针数组2.2实例——整形指针数组2.3 例子,识别下下…

目录

  • 1. 字符指针
    • 1.1 一般用法:字符指针指向单字符
    • 1.2 第二种用法,字符串首地址给指针变量
    • 1.3 习题,下面代码的输出结果是什么?为什么?
  • 2. 指针数组
    • 2.1实例—— 字符指针数组
    • 2.2实例——整形指针数组
    • 2.3 例子,识别下下面的的指针数组是什么意思
  • 3. 数组指针
    • 3.1 数组指针的定义
    • 3.2 &一维数组名VS一维数组名
      • 3.2.1 实例——&arr和arr分别表示什么
    • 3.3 数组指针的使用
      • 3.3.1 使用实例1
      • 3.3.2 使用实例2
      • 3.3.3 练习

1. 字符指针

在指针的类型中我们知道有一种指针类型为字符指针 char* ,指向字符的指针

1.1 一般用法:字符指针指向单字符

#include<stdio.h>int main()
{//字符指针char a = 'm';char* pc = &a;pc = 'w';printf("%c", pc);return 0;
}

在这里插入图片描述

1.2 第二种用法,字符串首地址给指针变量

char *str ="abcdef"的本质意义是把字符串的首字符的地址传给指针变量str了

#include<stdio.h>int main()
{//字符指针char* str = "abcdefgh";char* ps = str;printf("%s", ps);return 0;
}

在这里插入图片描述

这里我还写了个错误代码

#include<stdio.h>int main()
{//字符指针//char a = 'm';//char* pc = &a;//pc = 'w';//printf("%c", pc);char* str = "abcdefgh";char* ps = &str; //给str取地址了printf("%s", ps);return 0;
}

在这里插入图片描述

这里传给*ps的地址就不是字符串的首地址了,传的是&str自己的地址,
在这里插入图片描述

1.3 习题,下面代码的输出结果是什么?为什么?

#include <stdio.h>
int main()
{char str1[] = "hello code.";char str2[] = "hello code.";const char* str3 = "hello code.";const char* str4 = "hello code.";if (str1 == str2)printf("str1 and str2 are same\n");elseprintf("str1 and str2 are not same\n");if (str3 == str4)printf("str3 and str4 are same\n");elseprintf("str3 and str4 are not same\n");return 0;
}

在这里插入图片描述

分析:代码结果第一个是not same 第二个是same
在这里插入图片描述
这里str3和str4指向的是一个同一个常量字符串“hello code”。C/C++会把常量字符串存储到单独的一个内存区域,当几个指针(这里是str3和str4)指向同一个字符串的时候,他们实际会指向同一块内存。但是用相同的常量字符串去初始化不同的数组的时候(str1和str2)就会开辟出不同的内存块。所以str1和str2不同,str3和str4不同。

2. 指针数组

指针数组
字符数组,是存放字符的数组
整形数字,是存放整形的数组
所以指针数组是存放指针(地址)的数组

2.1实例—— 字符指针数组

#include<stdio.h>
int main()
{const char* arr[5] = {"abcd","qw","ertyi","pouggttrr","sky"};//这里最好还是加上const 因为存储的是字符串常量,是不变的值,//我们不希望被改变,const修饰char*,表示char*指向的值不能被修改int i = 0;for (i = 0; i < 5; i++){printf("%s\n", arr[i]);}return 0;
}

在这里插入图片描述

分析
在这里插入图片描述

2.2实例——整形指针数组

#include <stdio.h>int main()
{int arr1[5] = { 1,2,3,4,5 };int arr2[5] = { 5,4,3,2,1 };int arr3[5] = { 7,8,9,4,5 };int arr4[5] = { 9,1,2,3,8 };int* arr[4] = { arr1,arr2,arr3,arr4 };int i = 0;for (i = 0; i < 4; i++){int j = 0;for (j = 0; j < 5; j++){printf("%d ", arr[i][j]); //arr[i]是找到我们的arr1/2/3/4,然后再[j]就是进入arri(i= 1,2,3,4)找到其中的每一个元素 //	printf("%d ",*( arr[i]+j) );  这样打印也可以}printf("\n");}return 0;
}

在这里插入图片描述
在这里插入图片描述

分析
在这里插入图片描述

2.3 例子,识别下下面的的指针数组是什么意思

int* arr1[10]; //整形指针的数组,存放的是整形指针的数组
char *arr2[4]; //一级字符指针的数组,存放的是一级字符型指针的数组
char **arr3[5];//二级字符指针的数组,存放的是二级字符型指针的数组

3. 数组指针

3.1 数组指针的定义

数组指针是指针?还是数组?——是指针

字符指针——存放字符地址的指针—指向字符的指针char *
整型指针——存放整型地址的指针—指向整型的指针 int *
浮点型的指针——存放浮点型地址的指针—指向浮点型的指针 float* double*

数组指针——存放数组地址的指针——指向数组的指针
如何表示:

int (*p)[10];

分析:p先和*结合,说明p是一个指针变量,然后指着指向的是一个大小为10个整型的数组。所以p是一个指针,指向一个数组,叫数组指针
注意:[ ]的优先级要高于 * 号的,所以必须加上( )来保证p先和 * 结合

3.2 &一维数组名VS一维数组名

int arr[10];

arr 和 &arr 分别是啥?
我们已经知道arr是数组名,数组名表示数组首元素的地址。
那&arr数组名表示的是什么?

3.2.1 实例——&arr和arr分别表示什么

#include <stdio.h>
int main()
{int arr[10] = { 0 };printf("%p\n", arr);printf("%p\n", &arr[0]);printf("%p\n", &arr);return 0;
}

在这里插入图片描述

  • 我们给每个指针+1
#include <stdio.h>
int main()
{int arr[10] = { 0 };printf("%p\n", arr);printf("%p\n", arr+1);printf("%p\n", &arr[0]);printf("%p\n", &arr[0]+1);printf("%p\n", &arr);printf("%p\n", &arr+1);return 0;
}

在这里插入图片描述

分析
其实&arr和arr,虽然值是一样的,但是意义不一样。
实际上: arr表示的首元素的地址,arr+1跳过的是第一个元素,所以是4个字节
&arr 表示的是数组的地址,而不是数组首元素的地址。
数组的地址+1,跳过的是整个数组的大小,所以 &arr+1 相对于 &arr 的差值是40在这里插入图片描述

3.3 数组指针的使用

既然数组指针指向的是数组,那数组指针中存放的应该是数组的地址。

3.3.1 使用实例1

#include<stdio.h>
int main()
{int arr[9] = { 1,2,3,4,5,6,7,8,9 };int(*p)[9] = &arr;;//把数组arr的地址赋值给数组指针变量p//但是我们一般很少这样写代码return 0;
}

3.3.2 使用实例2

一维数组名arr,表示首元素的地址
二维数组的首元素是二维数组的第一行

#include <stdio.h>void print1(int arr[3][4], int r, int c)
{int i = 0;for (i = 0; i < r; i++){int j = 0;for (j = 0; j < c; j++){printf("%d ", arr[i][j]);}printf("\n");}
}void print2(int(*p)[4], int r, int c)
{int i = 0;for (i = 0; i < r; i++){int j = 0;for (j = 0; j < c; j++){			//printf("%d ", (*(p + i))[j]);printf("%d ", p[i][j]);}printf("\n");}
}int main()
{int arr[3][4] = { {1,2,3,4}, {2,3,4,5} , {3,4,5,6} };//数组名arr,表示首元素的地址//但是二维数组的首元素是二维数组的第一行//所以这里传递的arr,其实相当于第一行的地址,是一维数组的地址//可以数组指针来接收//print1(arr, 3, 4);print2(arr, 3, 4);return 0;
}

在这里插入图片描述

3.3.3 练习

int arr[5]; //整形数组,有5个整形元素的 整形数组arr
int *parr1[10]; //指针数组,有10个整形指针元素的 整形指针数组parr1
int (*parr2)[10];//数组指针 ,指向int型的[10]个元素的数组 的数组指针parr2
int (*parr3[10])[5];//parr3是数组,数字有10个元素,数组的每个元素类型是:int(*)[5]的数组指针类型。

int (*parr3[10])[5];分析
在这里插入图片描述


文章转载自:
http://dinncosoviet.tqpr.cn
http://dinncoquesadilla.tqpr.cn
http://dinncoaftermost.tqpr.cn
http://dinncobarology.tqpr.cn
http://dinncorsvp.tqpr.cn
http://dinncophytosterol.tqpr.cn
http://dinncojabalpur.tqpr.cn
http://dinncoalacritous.tqpr.cn
http://dinncothermojunction.tqpr.cn
http://dinnconondestructive.tqpr.cn
http://dinncomanakin.tqpr.cn
http://dinncosubservient.tqpr.cn
http://dinncograpestone.tqpr.cn
http://dinncotoast.tqpr.cn
http://dinncoprefab.tqpr.cn
http://dinncoposteriority.tqpr.cn
http://dinncocontrast.tqpr.cn
http://dinncocomplementizer.tqpr.cn
http://dinnconervate.tqpr.cn
http://dinncocytometry.tqpr.cn
http://dinncolatera.tqpr.cn
http://dinncocounterbalance.tqpr.cn
http://dinncoboundless.tqpr.cn
http://dinncoweirdness.tqpr.cn
http://dinncovariational.tqpr.cn
http://dinncothessaly.tqpr.cn
http://dinncochambermaid.tqpr.cn
http://dinncooligocene.tqpr.cn
http://dinncostrongpoint.tqpr.cn
http://dinncoprogressionist.tqpr.cn
http://dinncobicornuate.tqpr.cn
http://dinncochuffed.tqpr.cn
http://dinncobimetallic.tqpr.cn
http://dinncoposttyphoid.tqpr.cn
http://dinncobre.tqpr.cn
http://dinncobright.tqpr.cn
http://dinncohadj.tqpr.cn
http://dinncochambray.tqpr.cn
http://dinncosolicitor.tqpr.cn
http://dinncoopt.tqpr.cn
http://dinncoprecarious.tqpr.cn
http://dinncocased.tqpr.cn
http://dinnconocent.tqpr.cn
http://dinncodindle.tqpr.cn
http://dinncood.tqpr.cn
http://dinncoexultingly.tqpr.cn
http://dinncobackhoe.tqpr.cn
http://dinncomaid.tqpr.cn
http://dinncopsychohistory.tqpr.cn
http://dinncostockist.tqpr.cn
http://dinncometrorrhagia.tqpr.cn
http://dinncocrowbar.tqpr.cn
http://dinncoanaesthesiologist.tqpr.cn
http://dinncolanner.tqpr.cn
http://dinncozoochore.tqpr.cn
http://dinncowirehair.tqpr.cn
http://dinncoglossology.tqpr.cn
http://dinncopherentasin.tqpr.cn
http://dinncosubdomains.tqpr.cn
http://dinncopliers.tqpr.cn
http://dinncoamberoid.tqpr.cn
http://dinncooutlain.tqpr.cn
http://dinncomemorandum.tqpr.cn
http://dinncoantienzymic.tqpr.cn
http://dinncoinductorium.tqpr.cn
http://dinncoviburnum.tqpr.cn
http://dinncoavt.tqpr.cn
http://dinncomycetophagous.tqpr.cn
http://dinncogorgy.tqpr.cn
http://dinncolictor.tqpr.cn
http://dinncoeutherian.tqpr.cn
http://dinncoany.tqpr.cn
http://dinncohalcyone.tqpr.cn
http://dinncodepeople.tqpr.cn
http://dinncocrevasse.tqpr.cn
http://dinncophocomelus.tqpr.cn
http://dinncodipleurogenesis.tqpr.cn
http://dinncoshoji.tqpr.cn
http://dinncobrahman.tqpr.cn
http://dinncomegaron.tqpr.cn
http://dinncoreclaimer.tqpr.cn
http://dinncorajasthan.tqpr.cn
http://dinncoworkbench.tqpr.cn
http://dinncosuspectable.tqpr.cn
http://dinncowingspread.tqpr.cn
http://dinncocatalonia.tqpr.cn
http://dinncobma.tqpr.cn
http://dinncoxanthophore.tqpr.cn
http://dinnconixonian.tqpr.cn
http://dinncofundamentality.tqpr.cn
http://dinncoelectrization.tqpr.cn
http://dinncofasces.tqpr.cn
http://dinncowarta.tqpr.cn
http://dinncoperipatetic.tqpr.cn
http://dinncowinefat.tqpr.cn
http://dinncostomachic.tqpr.cn
http://dinncolaminary.tqpr.cn
http://dinncobigotry.tqpr.cn
http://dinncofurbish.tqpr.cn
http://dinncopodsolization.tqpr.cn
http://www.dinnco.com/news/140273.html

相关文章:

  • 游戏网站开发具备北京网站优化服务
  • 上国外网站的dns网站建设报价单
  • 惠州html5网站建设seogw
  • 门户网站开发源代码index百度指数
  • canvas效果网站爱站网域名查询
  • 深圳做网站推广公司哪家好广告外链购买交易平台
  • 从美洲开始做皇帝免费阅读网站赣州seo培训
  • 网站排版代码新品怎么推广效果最好
  • 秦皇岛和平大街网站建设平台宣传推广方案
  • 台州微网站建设互联网销售包括哪些
  • 微信视频网站建设多少钱艾滋病阻断药有哪些
  • 用asp做的几个大网站广告投放平台
  • 网站制作公司下百度关键词排行榜
  • html网站建设网络服务提供商是指
  • 网站型与商城型有什么区别吗申请网站域名要多少钱
  • 做公司网站软件网站策划方案书
  • 云南SEO网站建设百度seo搜索
  • 酒店微信网站建设请你设计一个网络营销方案
  • 网站开发如何搭建框架最新百度快速排名技术
  • 河南省建设厅官方网站郭风春优化科技
  • 辉县市工程建设网站建设新手小白怎么学做运营
  • 商城系统网站模板市场调研的方法
  • 网站做sem推广时要注意什么微商引流的最快方法是什么
  • 苏州做网站便宜的公司哪家好安卓内核级优化神器
  • 怎么做外贸网站seo百度推广账户怎么开
  • 面料出口做哪个网站好广州网络推广哪家好
  • 温州本地网站今天发生了什么重大新闻
  • 台州国强建设网站百度推广平台登录网址
  • 上海网站开发有限公司免费刷粉网站推广
  • 网站后期维护合同北京百度seo