char * p1[3]二维数组名和二维数组指针做函数参数

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int myPrintf6(char **p,int *dep,int * len){
int lenth = *len;
int depth = *dep;
printf(“-----------------\n”);
printf(“%s\n”,func);
for(int i=0; i<depth; i++) {
for(int j=0; j<lenth; j++) {
printf(“%d\n”,p[i][j]);
}
}
return 0;
}

int myPrintf7(char *(*p)[3],int *dep,int * len){
int lenth = *len;
int depth = *dep;
printf(“-----------------\n”);
printf(“%s\n”,func);
for(int i=0; i<depth; i++) {
for(int j=0; j<lenth; j++) {
printf(“%d\n”,(*p)[i][j]);
}
}
return 0;
}

int main() {

int len2 = 3;
int dep2 = 2;


char * p1[3] = {"aaa","bbb"};
myPrintf6(p1,&dep2,&len2);//p把二维数组首地址拷贝给形参
myPrintf7(&p1,&dep2,&len2);//&p把二维数组地址拷贝给形参

return 0;

}

猜你喜欢

转载自blog.csdn.net/katerdaisy/article/details/132492214