In the array parameter declared by the function, and specify the length of the array. In C, a single function is allowed to manipulate any lengthOne-dimensional array. The disadvantage of this feature is that the function cannot know the length of the array. If you really need to know the length of the array, you must pass it to the function as a separate parameter.
When the array name is used as a real parameter, the pointer passed to the function is actually a pointer to the starting position of the array.
/* Development Environment: vs2010 Window XP SP3 */# include <stdio. h> int main (void) {void array_len (int v []); int V [] = {70, 30, 40, 60, 10, 20, 50,100, 80, 90}; int Len; array_len (V); Len = sizeof (v)/sizeof (INT); // 40/4 = 10, sizeof (V) returns the total number of elements in a one-dimensional array: 10*4 printf ("% d \ n", Len); // 10 return 0 ;} void array_len (int v []) {int Len = sizeof (v)/sizeof (INT); // 4/4 = 1, sizeof (V) returns the length of the int * P pointer, which is 4 bytes printf ("% d \ n", Len); // 1}
The same result is returned when the int value is changed to long.
Note that:
Pointers and long int occupy the same word width, that is, the maximum addressing width of the machine, and 32 bits are 4 bytes.