(1) sizeof
Method: sizeof (array name)/sizeof (array type name)
Note: If the byte occupied by the array is divided by the byte occupied by the array type, the result is the number of array elements.
(2) strlen
Description: strlen, returns the Valid String Length.
Method: strlen (character array name) // returns the valid character length of the character array, excluding '/0' at the end'
Note:
When the array is passed as the number of functions, the array name represents the first address of the array instead of the array content, so sizeof and strlen cannot be used;
Therefore, when transferring an address, provide two numbers of records: one is the array name, representing the first address of the array; the other is the number of array elements to determine the number of passes. For example: # include <iostream>
Using namespace STD;
Void sum (INT array [])
{
Cout <"sizeof (array) =" <sizeof (array) <Endl;
}
Void main ()
{
Int A [] = {1, 2, 4, 5, 6, 7, 8, 9, 10 };
Cout <"sizeof (A) =" <sizeof (a) <Endl;
Sum ();
} Calculation result:
Sizeof (A) = 40
Sizeof (array) = 4 Analysis: When the array is passed as the number of functions, the array name represents the first address of the array, that is, the pointer, rather than the array content. If the entire array is passed, stack overflow will occur. Therefore, in the main function, sizeof is used to calculate the exact array length. In the call function, because the transmitted array is no longer the array itself, but its address, it is actually the length of the array address calculated using sizeof. In this case, sizeof (array ), it is actually sizeof (INT ).