//二维数组传参问题示例
#include<iostream>
using namespace std;
//方法1:传递数组,注意第二维必须标明
void fun1(int arr[][3],int iRows)
{
for(int i=0;i<iRows;i++)
{
for(int j=0;j<3;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
void fun2(int (*arr)[3],int iRows)
{
for(int i=0;i<iRows;i++)
{
for(int j=0;j<3;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
void fun3(int*arr,int iRows,int iCols)
{
for(int i=0;i<iRows;i++)
{
for(int j=0;j<3;j++)
{
cout<<*(arr+i*iRows+j)<<" ";
}
cout<<endl;
}
cout<<endl;
}
int main()
{
int a[2][3]={{1,2,3},{4,5,6}};
fun1(a,2);
cout<<endl;
fun2(a,2);
cout<<endl;
//此处必须进行强制类型转换,因为a是二维数组,而需要传入的是指针
//所以必须强制转换成指针,如果a是一维数组则不必进行强制类型转换
//为什么一维数组不用强制转换而二维数组必须转换,此问题还没解决,期待大牛!
fun3((int*)a,2,3);
cout<<endl;
}
/*
#include<iostream>
using namespace std;
void fun(int *a,int length)
{
int i;
for(i=0;i<length;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
int main()
{
int a[4]={1,2,3,4};
fun(a,4);
cout<<endl;
return 0;
}
*/
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有