本帖最后由 bin554385863 于 2019-12-9 17:32 编辑 #include <iostream>
void func(int (*ptr)[3], int c)//二维数组做为函数的形参
{
for (size_t i = 0; i < 3; i++)
{
for (size_t j = 0; j < c; j++)
{
std::cout << ptr[i][j];
}
std::cout<<std::endl;
}
}
int main(int argc, char const *argv[])
{
int arr[3][3] = {1,2,3,4,5,6,7,8,9};
func(arr, 3);
return 0;
}
-----------------------------------------------------------------------------
Microsoft Windows [版本 10.0.18363.476]
(c) 2019 Microsoft Corporation。保留所有权利。
E:\Users\admin\Documents\VScode\Code>c:\Users\admin\.vscode\extensions\ms-vscode.cpptools-0.26.2\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-5l5uyoe2.wdh --stdout=Microsoft-MIEngine-Out-s4enc20k.axl --stderr=Microsoft-MIEngine-Error-qa5h0kwm.lzh --pid=Microsoft-MIEngine-Pid-ihivnbk2.0dg --dbgExe=D:\MinGW\bin\gdb.exe --interpreter=mi
123
456
789
E:\Users\admin\Documents\VScode\Code>
==================================
对于二维数组int arr[m][n]来说,它的类型是int (*)[m]. |