C++ 二维数组作为形参传递使用实例

在线代码编辑器: http://codepad.org/

1、*指针

 1 void display(int *arr, const int row, const int col)
 2 {
 3     for(int i=0; i < row ; ++i)
 4     {
 5         for(int j=0; j < col; ++j)
 6         {
 7             cout<< *(arr + i*col + j)<<" "; 
 8         }
 9         cout<<endl;
10     }
11     cout<<endl;
12 }

 

2、**指针

 1 void display2(int **arr, const int row, const int col)
 2 {
 3     for(int i=0; i < row ; ++i)
 4     {
 5         for(int j=0; j < col ; ++j)
 6         {
 7             cout<< *((int*)arr + i * col + j) << " "; 
 8         }
 9         cout<<endl;
10     }
11     cout<<endl;
12 }

 

posted @ 2018-07-20 10:18  戒骄戒躁-沉淀积蓄  阅读(210)  评论(0)    收藏  举报