I passed a array to function and tried to find the length of the array . but the result was not expected . can anybody explain please?
int main()
{
int arra
When you pass an array into a function as a parameter, the array decays into a pointer to the beginning of the array. A pointer has no meta information stored in it unlike the array. A good practice is to pass the size to the function as an additional parameter.
void func(int *arr, int size);
Here's what C standard says (C99 6.3.2.1/3 - Other operands - Lvalues, arrays, and function designators):
Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points to the initial element of the array object and is not an lvalue
So, once you pass it to the function - Inside the function, it's no more an array, it's a pointer.