user60405: When passing an array to a function, you usually pass the length of the array along with it. You can compute the size of the array with sizeof(myArray)/sizeof(myArray[0]), which works just fine.
However, if you try to do this within the function that you pass the array to, this doesn't return the length of the array - eg. if it is an int array, it returns 1, if it is a double array, it returns 0.
Why is that so and is there any way to compute the size of an array that was passed as a parameter?

user4143: You can't. You are passing a pointer to the array, and sizeof will give you the size of that pointer (2 on an 8-bit Arduino).
Instead the normal way is to pass the size of the array as a parameter to your function.
myFunction(myArray, sizeof(myArray) / sizeof(myArray[0]));


60405: <p>When passing an array to a function, you usually pass the length of the array along with it. You can compute the size of the array with <code>sizeof(myArray)/sizeof(myArray[0])</code>, which works just fine.</p>

<p>However, if you try to do this within the function that you pass the array to, this doesn't return the length of the array - eg. if it is an <code>int</code> array, it returns 1, if it is a <code>double</code> array, it returns 0.</p>

<p>Why is that so and is there any way to compute the size of an array that was passed as a parameter?</p>
 4143: <p>You can't. You are passing a <em>pointer</em> to the array, and <code>sizeof</code> will give you the size of that pointer (2 on an 8-bit Arduino).</p>

<p>Instead the normal way is to pass the size of the array as a parameter to your function.</p>

<pre><code>myFunction(myArray, sizeof(myArray) / sizeof(myArray[0]));
</code></pre>
