您的位置:首页 > 其它

二维数组指针作为函数参数传递

2017-03-25 23:24 253 查看
以前二维数组作为函数参数传递我都是这么写的void def(int a[][10])。传递一个二维数组a,(其中第二维要确定大小)其实想一想挺合理的...

后来,发现还有这种写法 void def(int(*a)[10]);

/* ***********************************************
Author        :guanjun
Created Time  :2017/3/18 13:32:52
File Name     :33.cpp
************************************************ */
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
void dfs(int (*a)[10]){
for(int i=0;i<5;i++){
for(int j=0;j<10;j++){
cout<<a[i][j]<<" ";
}
}
}
void dfs2(int a[][10]){
for(int i=0;i<5;i++){
for(int j=0;j<10;j++){
cout<<a[i][j]<<" ";
}
}
}
int main(){

int (*a)[10]=new int[5][10];
for(int i=0;i<5;i++){
for(int j=0;j<10;j++){
a[i][j]=i*j;
}
}
dfs(a);
dfs2(a);
delete []a;
return 0;
}


其实,还有这种次而发 void def(int **a)



我提的弱智问题...http://stackoverflow.com/questions/43018146/what-is-the-difference-between-the-two-wording-when-the-two-dimensional-array-is/43018294?noredirect=1#comment73125242_43018294
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: