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

以前二维数组作为函数参数传递我都是这么写的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

原文地址:https://www.cnblogs.com/pk28/p/6618987.html