When an array is used as a function parameter, this parameter degrades to a pointer and cannot be used to directly obtain the array size.
The array is passed to a function. The array type is automatically converted to the pointer type, so the actual address is passed.
Void func (INT array [10])
Void func (INT array [])
Void func (int * array)
Therefore, the above three function declarations are completely equivalent.
The actual situation is that the array is used as a parameter and cannot be passed by value at all. This is determined by the implementation mechanism of C/C ++ functions.
The calculation of the array size is usually as follows:
Int Len = sizeof (ARR)/sizeof (type)
Obtain the length of the Array Based on the relationship between the total length and the length of a single element.
But as the form parameter, the length of sizeof (ARR) is 4, that is, the length of a pointer.
There are two ways to solve this problem:
Method 1.
When passing parameters, add a parameter directly as the length of the array.
Method 2. (incorrect)
Int * P = A [0];
Int ilen = 0;
While (P! = NULL)
{
Ilen ++;
* P ++;
}