zoukankan      html  css  js  c++  java
  • 二维数组指针作为函数参数传递

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

  • 相关阅读:
    函数三
    函数二
    函数一
    python数据类型和编码补充
    Python基础数据类型考试题
    VS2017设置C++标准
    std::weak_ptr
    Visual Assist 配色
    JMeter
    fcgi返回状态码
  • 原文地址:https://www.cnblogs.com/pk28/p/6618987.html
Copyright © 2011-2022 走看看