二级指针的3种内存模型

二级指针的内存模型


二级指针的第一种内存模型


Char*Accary [ ]
={ “aaaaaa”, ”bbbbbb”, ”ccccccc” };

//接口形参使用方式

Intprintfarr(char
**ArrayStr,int iNUm)

{

For(i =0; i<iNUm; i++)

{

Printf(“%s \n”, ArrayStr[i]);

}

}

//调用方式

Printfarr(Accary, 3);


二级指针的第二种内存模型


CharArray[10][30]
={“aaaa”, “bbbb”, “cccccc”,};

//接口形参使用方式

Voidabc(char Arrary[30],4 )

{

For(i=0; i<4; i++)

{

Printf(“%s \n”,Accary[i]);

}

}

//调用方式

Printfarr(Array, 3);


二级指针的第三钟内存模型


char**real = (char **)malloc(3*sizeof(char *));

for(int i=0; i<3; i++)

{

real[i]= (char *)malloc(30*sizeof(char));

}

sprintf(real[0],"dbsiudaudhakdhjhba");

sprintf(real[1],"b");

printf("%s\n", real[1]);

//接口形参使用方式

Intprintfarr(char
**ArrayStr,int iNUm)

{

For(i =0; i<iNUm; i++)

{

Printf(“%s \n”, ArrayStr[i]);

}

}

//调用方式

Printfarr(Accary, 3);

形参写法的引申:


Voidstr(char abc[30]);

voidstr(char abc[ ]);
一维数组做形参,退化为指针

voidstr(char abc);手工加*,手工完成编译器任务


//针对第二种内存模型

Voidstr(char abc[30][60]);

voidstr(char abc[ ][60]);
二维数组做形参,退化为指针,60为指针步长

voidstr(char (*abc)[60]);手工加*,手工完成编译器任务,其实就是数组指针

等价关系


数组参数 等效指针参数

一维数组chara[ 30 ] ------------------------------->
指针char× a

指针数组char × a [ 30]-------------------------------->指针的指针char×
× a

二位数组chara[30 ][30]-------------------------------->数组的指针char(×a)[30]

时间: 2024-12-11 13:00:32

二级指针的3种内存模型的相关文章

二级指针的三种内存模型

第一种内存模型: /* Module: 二级指针第一种内存模型.cpp Notices: Copyright (c) 2017 Landy Tan */ #include <iostream> using namespace std; ///////////////////////////////////////////////// #define SIZE(a) sizeof(a) / sizeof(a[0]) int SortArray(char **pArray, int nLen);

C++二级指针第三种内存模型

#include "stdio.h" #include "stdlib.h" #include "string.h" void main() { int i = 0, j = 0; char buf[100]; char **myarray = (char **)malloc(10*sizeof(char*)); //int array[10] if (myarray == NULL) { return; } for (i=0; i<10;

C提高_day03_二级指针做输入第2种内存模型

#include <stdlib.h> #include <string.h> #include <stdio.h> //打印 排序 //封装成函数 void main() { int i = 0, j = 0; int num = 4; char tmpBuf[30]; char myArray[10][30] = {"aaaaaa", "ccccc", "bbbbbbb", "1111111111

C++二级指针第二种内存模型(二维数组)

C++二级指针第二种内存模型(二维数组) 二维数组 二维数组本质上是以数组作为数组元素的数组,即“数组的数组”. 定义 类型说明符 数组名[常量表达式][常量表达式] 例如: float a[3][4],b[5][10]; 二维数组元素地址 #include <iostream> using namespace std; int main() { cout << "Hello world!" << endl; int a[3][4]={ {1,2,3

二级指针三种内存模型综合训练

/*** point_practice.c ***/ #include<stdio.h> #include<string.h> #include<stdlib.h> int sort( char **myp1 /*in*/, int num1, char (*myp2)[30], int num2, char ***myp3, int *num3) { int i = 0, j = 0, k = 0; int tmplen; char **p3 = NULL; char

实现按行读取文件,把内容按照第三种内存模型打包数据传出,把行数通过函数参数传出。

/* 2 编写一个业务函数,实现按行读取文件.把内容按照第三种内存模型打包数据传出,把行数通过函数参数传出. 函数原型有两个,任意选择其一 要求1:请自己任意选择一个接口(函数),并实现功能:70分 要求2:编写测试用例.30分 要求3:自己编写内存释放函数 */ /********************************************************************** * 版权所有 (C)2015, Wu Yingqiang. * * 文件名称:ReadFi

用2种内存模型来排序字符串的的顺序,一种是交换内存地址,第二种是交换内存里面的值;

#define _CRT_SECURE_NO_WARNINGS #include"stdio.h" #include"stdlib.h" #include"string.h" void MyPrintf(char **); void MYSORT(char **, int); void SORTBUF(char **); void main() { int i = 0; int j = 0; char *buf; char **myarray;

二级指针做输入的第三种内存模型:手工打造二维内存

声明局部变量p, p指向一段内存地址,这段内存地址存放这N个指针,每个指针都指向malloc的另一段内存. 内存模型图如下: p应该是二级指针 #define _CRT_SECURE_NO_WARNINGS#include<stdlib.h>#include<stdio.h>#include<string.h>#include<ctype.h> char**getMem(int num){ int i = 0, j = 0; char** p2 = NULL

C、C++: 引用、指针、实例、内存模型、namespace

// HelloWorld.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "string.h"#include "iostream.h" /** * 在C.C++语言中 * 声名语句中: 声明指针变量用*,声明变量或者常量都不加*. * 譬如函数声明中的参数,返回值类型等.例如类中的字段的声明. * 在赋值语句中