Directly on the code:
#include
void Fun (int *a[],int m,int N)//
{
printf ("%d\t", *a);//[0][0]
/*
int e[2][2][2]={8,7,6,5,4,3,2,1};
int *f,***g;
g=e;
f=e;//a warning, but not an error.
printf ("%d\n", *f);
*/
}
/* Explanation:
The int *a[2] in fun () means that the pointer array a[2],a[0],a[1] is stored as pointers,
A represents the first address of an array, so it is equivalent to a level two pointer. (explains why an argument is a level two pointer)
A since it is a pointer, when the value is assigned, the pointer value of the argument is copied to a, so *a represents a[0][0];
The level of the pointer can only indicate that the pointer is also a pointer to the multilevel, and when the parameter is passed, the pointer level is checked.
But the pointer stores all the address values, and after the address values change, such as the storage space that stores the int data, the
The first plus * means the int number.
You can assign values between pointers of different levels. (explained *a=4, but **a is wrong) */
void Fun1 (int (*a) [],int m,int N)//int **a will have warning
{
printf ("%d\t", **a); int (*a) [2] can be fully manipulated with an array
int (*a) [] can only manipulate data with pointers
}
/* if int (*a) []; array pointer, pointer to array, level two pointer;
Represents the address of the array a[], old Tam calls the "line pointer" */
int main ()
{
int a[3][2]={4,5,6,1,2,3};
Fun ((int * *) a,3,2);//
FUN1 (a,3,2);//(int * *)
return 0;
}
Summarize:
1. Function parameter: The parameter is a simple copy of the argument
2. Array parameters cannot check the length of the array (defined size)
3. Two-dimensional array parameters (multidimensional arrays can be converted to two-dimensional or one-dimensional arrays):
1. Forced conversion to one-dimensional pointer, one-dimensional array
2. Through the row pointer
3. Force conversion to a two-dimensional pointer (meaningless). After a parameter is passed, it can only be accessed by a pointer, and the array form no longer applies.
Therefore, if the number of rows and the number of columns are indeterminate, two-dimensional array parameters are not necessary to become a two-dimensional array. Since the parameters are addressed in the same way as one-dimensional arrays, it is better to force conversions directly into one-dimensional arrays.
For a two-dimensional array determined by the number of columns, the parameter can be converted to a two-dimensional array.
If the formal parameter is defined as int a[][6]; It is convenient to access the array as the original argument after the parameter is passed.
4. When the array is passed as a non-reference type, the array is automatically converted to a pointer of the same type, that is, a copy initialized to the corresponding type argument.
When a function is called, the function actually operates a copy of the pointer without modifying the value of the argument pointer, but the value of the array element can be changed by the pointer. --From the network
My point of view: Reference passing is also a simple copy, but it is more of a pointer, you can manipulate the target data by the pointer (it appears to be right after validation)
Reference delivery: (from Baidu Encyclopedia)
In C + +, function arguments are passed in a reference pass.
The so-called reference passing means that when the function is called, the address of the actual parameter is passed to the function, then the changes in the function squadron parameters will affect the actual parameters.
5. Parameter passing:
When a function is completed, the parameter is passed, if the argument needs to be changed, it is best to implement the operation and change of the argument by reference passing. The return value is best used to return the execution state of the function to make it easier to check the execution of the called function in the calling function and to prompt.