A[int1][int2]
instantce:A[1+2]or i=3;A[i+2]
//-------------------------------------------------------
A[][2]={1,2,3,4} equals to A[2][2]={{1,2},{3,4}}
//--------------------------------------------------------
//--------------------------------------------------------
void sum(int a[][4],int n) //int a[][4] not int a[3][], and be constant
for (int i=0;i<n;i++)
{
for (int j=1;j<4;j++)
a[i][0]+=a[i][j]; //change the first value to get the sum
}
}
main()
{
int Table[3][4]={{1,2,3,4},{2,3,4,5},{3,4,5,6}};
//-----------------------------------------------------
for(int i=0;i<3;i++) //
cout<<"The sum is "<<Table[i][0]<<endl; //before change
int comp=Table[0][0]; //to compare
//-----------------------------------------------
sum(Table,3);
for(int i=0;i<3;i++)
cout<<"The sum is "<<Table[i][0]<<endl; //after change
//------------------------------------------------------
cout<<Table[0][0]<<'' ''<<comp<<'' ''<<Table[0][1]<<endl;// compare
//-------------------------------------------------------
cout<<Table<<" "<<&Table[0][1]<<" "<<&Table[0][2];// a pointer and arranged one by one
cin>>'''';
}
c++学习笔记(数组)
最新推荐文章于 2025-09-06 21:38:00 发布