将多维数组用指针传递

2021-01-19  本文已影响0人  yuerxiaoshui
#include <string>
#include <iostream>
#include <vector>

using namespace std;

void print(double **tab,int rows,int cols)
{
    for(int i=0;i<rows;i++){
        for(int j=0;j<cols;j++){
            cout<<*((double *)tab+i*cols+j)<<" ";
        }
        cout<<endl;
    }
}
int main()
{
    double ta[2][3]={{1.0,2.0,3.0},{4.0,5.0,6.0}};
    print((double **)ta,2,3);
    return 0;
}

上一篇 下一篇

猜你喜欢

热点阅读