指针指针数组—多级指针—动态指针.ppt
文本预览下载声明
* 数组指针——以此类推 一维数组名是“列指针类型”----“元素指针类型” 指针变量的定义:int *p; 二维数组名是“行指针类型” 指针变量的定义:int (*p)[4] ; 三维数组名是“页指针类型” 指针变量的定义:int (*p)[3][4] ; 四维数组名是“块指针类型” 指针变量的定义:int (*p)[3][4][5] ; 圆括号是必须的 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. * 问题的提出 变量是用于存放单个数据的 数组是用于存放“同类型”的多个数据的 方便循环控制结构的编程 指针变量是用于存放单个地址号的 “同类型”的多个地址号是否能够集中存储在一起构成“指针数组”呢? Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. * 元素均为指针类型数据的数组,称为指针数组 定义形式为: 类型关键字 *数组名[数组长度]; 例如 char *pStr[5]; pStr [5] * char 四、指针数组 注意 没有 圆括号 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. * 例: 二维字符数组 void main() { int i; char str[][10] = {Pascal,Basic,Fortran, Java,Visual C}; for (i=0; i5; i++) { printf(%s\n, str[i]); } } str str[0] Pascal str[1] str[2] str[3] Basic Fortran Java 二维数组 Visual C str[4] Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. * 例:字符指针数组 void main() { int i; char *ptr[] = {Pascal,Basic,Fortran, Java,Visual C}; for (i=0; i5; i++) { printf(%s\n, ptr[i]); } } ptr[0] Pascal ptr[1] ptr[2] ptr[3] Basic Fortran Java ptr指针数组 字符串 ptr Visual C ptr[4] Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. * 例:字符串按字典顺序排序—二维数组编程 char str[N][10] = {Pascal,Basic,Fortran, Java,Visual C}; for (i=0; iN-1; i++) { for (j = i+1; jN; j++) { if (strcmp(str[j], str[i]) 0) { strcpy(temp,str[i]); strcpy(str[i],str[j]); strcpy(str[j],temp); } } } str str str str str str str str str str Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Lt
显示全部