Array with pointers.
The header addresses the past and then outputs the array elements through the address.
1. One-dimensional arrays
#include <iostream>using namespacestd; #include<cstring>voidFarray1 (intArray1[],intLen//Note: There is no way to get the length through array1, only by passing the parameter, because it is the first address of the array. { for(intI=0; i<len;i++) { //cout<<array1[i]<<endl;cout<<* (array1+i) <<endl;//because the first address is passed, both methods can output array elements }}voidFarray2 (int*array1,intLen//Note: There is no way to get the length through array1, only by passing the parameter, because it is the first address of the array. { for(intI=0; i<len;i++) { //cout<<array1[i]<<endl;cout<<* (array1+i) <<endl;//because the first address is passed, both methods can output array elements }}voidMain () {intmarks[5] = { +, -, the,Bayi, *}; intlength1=sizeof(marks)/4; Farray1 (MARKS,LENGTH1); Farray2 (MARKS,LENGTH1); System ("Pause");}
2, two-dimensional array:
#include <iostream>using namespacestd; #include<cstring>voidFarray1 (intarray1[][3],intLen1,intLEN2)//Note: There is no way to get the length through array1, only by passing the parameter, because it is the first address of the array. { for(intI=0; i<len1;i++) { for(intj=0; j<len2;j++) //cout<<array1[i][j]<<endl;cout<<* (* (array1+i) +j) <<endl;//because the first address is passed, both methods can output array elements }}voidFarray2 (int(*array1) [3],intLen1,intLEN2)//Note: To specify the number of array columns, you cannot pass{ for(intI=0; i<len1;i++) { for(intj=0; j<len2;j++) //cout<<array1[i][j]<<endl;cout<<* (* (array1+i) +j) <<endl;//because the first address is passed, both methods can output array elements }}voidMain () {intmarks[2][3] = {{ +, -, the},{Bayi, *, About}}; intlength1=sizeof(marks)/4;//get the total length of the array intLength2=sizeof(marks[0])/4;//get number of columns intLength3=length1/length2;//get the number of rowsfarray1 (marks,length3,length2); Farray2 (MARKS,LENGTH3,LENGTH2); System ("Pause");}
Two ways to pass an array to C + + functions