How to find out the length of the array pointed by a pointer?

This is a discussion on How to find out the length of the array pointed by a pointer? within the C Programming forums, part of the General Programming Boards category; Hi all,
i passed an array of integer
Code:
int myarr[10];
into a function like this:
Code:
int *function(int *array, ...

however when i tried to find out the length of myarr in the function using:

Code:

int arrSize = sizeof(array)/sizeof(int);

it returns only (i think) the size of the memory location *array pointed to, which is the start of myarr?

yes, an array isn't passe by value, there's an implicit conversion array-pointer and in the function you have a pointer to the first element, in fact in the function write array[3] or *(array+3) is the same thing.
That code works only in the function where the array is declared

How should i find out the length of myarr in the function without passing in one more argument?

you can't, you can use many solution if you strongly need a function with 1 parameter:
1)you can declare your array of the size needed +1 and assign to the last element in position [n-1] a special value (es -9999) you're sure that the element from 0 to n-2 can't assume
2) a struct, for example:

The parameters inArray and outArray are still passed implicitly as pointers, but C treats them as pre-initialized arrays for the purpose of the function. That means that NELEMS(inArray) will correctly give you the number of elements whether you use it inside the function or outside.

The parameters inArray and outArray are still passed implicitly as pointers, but C treats them as pre-initialized arrays for the purpose of the function. That means that NELEMS(inArray) will correctly give you the number of elements whether you use it inside the function or outside.

Nope. Try it out for yourself.

The arguments are still treated as pointers, and the "array sizes" are ignored by the compiler. They're not anything like a variable-length array. The sizeof operator gives you the size of a pointer, because it is only a pointer.

Within the function, the array may be indexed as if it were a VLA of size [y][x]. If the sizes were reversed, for instance, to `int a[x][y]' then the printed result will be different if x != y.

The first dimension is essentially always ignored*. With a two-dimensional array parameter, as in your example, only the second dimension must be specified, so sizeof then knows how big the array (in the second dimension) is. C99 just allows the size to be variable, similar to a VLA.

*The compiler might use the dimensions for optimizations, but the first dimension doesn't otherwise affect what the code does. I actually haven't had much need for passing multidimensional arrays to functions lately, and I haven't explored the various syntaxes that were introduced in C99.