When an array is a function, the parameter is degraded to a pointer, and the size of the array cannot be evaluated directly.
Pass an array to a function. The array type itself is actively converted to a pointer type, so the actual pass is the address.
void func (int array[10])
void func (int array[])
void func (int *array)
So the above three function declarations are completely equal.
The reality is. Array to do the number of references. It is completely impossible to pass by value.
This is determined by the implementation mechanism of the C + + function.
The usual way to calculate the size of an array is as follows:
int len = sizeof (arr)/sizeof (type)
Get the length of an array using the total length and the length of a single element
However, the length of sizeof (ARR) is always 4, which is the length of a pointer.
To do this, there are two ways to solve the problem:
Method 1.
When a parameter is passed, the length of the array is added directly to a number of parameters.
Method 2. (Is wrong)
int *p = a[0];
int ilen = 0;
while (P! = NULL)
{
? ? ilen++;
? ? *p++;
}
A c array is degenerate into a pointer when it is a shape.