1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#define COL 3
#define ROW 5
using namespace std;
int** Array(int arr[][ROW])
{
int **pd;
pd=new int*[COL];
for(int i=0; i<ROW; i++)
pd[i]=new int[ROW];
for(int i=0; i<COL; i++)
{
for(int j=0; j<ROW; j++)
{
pd[i][j]=arr[i][j];
}
}
//some code
return pd;
}
void free(int **p)
{
for(int i=0; i<ROW; i++)
delete [] p[i];
delete [] p;
}
int main()
{
int arr[COL][ROW]={{1,89,12,2,44},{23,5,32,16,18},{22,5,7,45,67}};
int **p;
p=Array(arr);
for(int i=0; i<COL; i++)
{
for(int j=0; j<ROW; j++)
{
cout<<p[i][j]<<" ";
}
cout<<endl;
}
free(p);
return 0;
}
|