Length of Array

Hi All
If I am passing an array to a function, is it possible to get the length of the array in the function?

I tried the following but it didnt work

1
2
3
4
5
6
void MyFunction( int a[])

int Length

Length=sizeof a/ sizeof (int)


Thanks
closed account (z05DSL3A)
No, pass the length into the function along with the array.

Edit: It appears that I forgot the word function above...fixed
Last edited on
An alternative is to use C++ container types such as vector.
closed account (zvRX92yv)
^ This ^

And sizeof is a preprocessor function, meaning it is replaced with the size before compilation.
Nahiyan wrote:
And sizeof is a preprocessor function, meaning it is replaced with the size before compilation.

That's not true. Sizeof is an operator.
Topic archived. No new replies allowed.