64,648
社区成员
发帖
与我相关
我的任务
分享
//二维数组指针做参数
//2013/6/29
#include <iostream>
using namespace std;
//二维数组指针做形参
void f(int (*pArray)[3][3])
{
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
cout << pArray[i][j] <<" ";
cout << endl;
}
cout << endl;
}
int main()
{
int a[3][3] =
{
{1,1,1},
{2,2,2},
{3,3,3}
};
f(&a);
return 0;
}
#include <iostream>
using namespace std;
//二维数组指针做形参
void f(int pArray[][3])//相当于void f(int (*pArray)[][3])
{
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
cout << pArray[i][j] <<" ";
cout << endl;
}
cout << endl;
}
int main()
{
int a[3][3] =
{
{1,1,1},
{2,2,2},
{3,3,3}
};
f(a);
return 0;
}
//二维数组指针做参数
//2013/6/29
#include <iostream>
using namespace std;
//二维数组指针做形参
void f(int pArray[3][3])
{
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
cout << pArray[i][j] <<" ";
cout << endl;
}
cout << endl;
}
int main()
{
int a[3][3] =
{
{1,1,1},
{2,2,2},
{3,3,3}
};
f(a);
return 0;
}
for(int j=0; j<3; j++)
cout << (*pArray)[i][j] <<" ";
指针二维数组的指针,用*消引用后才是二维数组。