#include <iostream > using namespace std; //-----------------------多维数组作为参数----------------------- //-----------------------用多维数组多维形参,并输出数组------- //-------这种参数的定义格式算是重载,不与一下格式重读 //-------错误:display' : cannot convert parameter 1 from 'int [3][3]' to 'int ** ',实参类型与之不匹配 //void display(int** a)//------编译器自动把它退化为指针,并不对其进行长度的检查。 //-------错误:'display' : cannot convert parameter 1 from 'int [3][3]' to 'int *[]' //void display(int* a[])//------编译器自动把它退化为指针,并不对其进行长度的检查。 //-------错误:'display' : cannot convert parameter 1 from 'int [3][3]' to 'int *[]' //void display(int *a[3])//------编译器自动把它退化为指针,并不对其进行长度的检查。 /**/ { cout<<"output by display(int ** a)"<<endl; for(int i =0;i< 3;i++)//-------这个循环输出数组中数据 for(int j =0;j< 3;j++) cout<<"/t"<<a[i][j]; } /* void display(int a[][3])//------编译器自动把它退化为指针,并不对其进行长度的检查。 { cout<<"output by display(int a[][3])"<<endl; for(int i =0;i< 3;i++)//-------这个循环输出数组中数据 for(int j =0;j< 3;j++) cout<<"/t"<<a[i][j]; } */ //------------出错:'int (*)[]' : unknown size,编译器会对长度进行检查?不是,是指针类型的检查, //void display(int (*a)[])//------编译器自动把它退化为指针,并不对其进行长度的检查。 //------------出错:void __cdecl display(int [][3])' already has a body.进过实验,编译器认为他和display(int a[][3])相同,属于重复定义的错误 /* void display(int (*a)[3])//------编译器自动把它退化为指针,并不对其进行长度的检查。 { cout<<"output by display(int a[][3])"<<endl; for(int i =0;i< 3;i++)//-------这个循环输出数组中数据 for(int j =0;j< 3;j++) cout<<"/t"<<a[i][j]; } */ /* //-----------display(int (&a)[3][3]) 使用时编译器检查长度,必须给两个[]赋值。其他的调用只赋值最后一个[],但它是引用传址必须给所有[]赋值 void display(int (&a)[3][3])//----------编译器会对长度进行检查 { cout<<"output by display(int (&a)[3][3])"<<endl; for(int i =0;i< 3;i++)//-------这个循环输出数组中数据 for(int j =0;j< 3;j++) cout<<"/t"<<a[i][j]; } */ using namespace std; void main() { int a[3][3]; for(int i =0;i< 3;i++) for(int j =0;j< 3;j++) a[i][j]= i*j +j+1; display(a); }#include <iostream > using namespace std; //- 你的当前访问异常,请进行认证后继续阅读剩余内容。 提交