Passing Arrays as arguments into custom void function.

Strange things that i dont understand is going on with a snippet of code. as the Subject hints to. i created a custom function to accept a int low number, int increment, and int array. if you want to find the size of an array you do sizeof(yourArray)/ sizeof(ArrayType) this works if i run that on the first array which is declared out of setup and loop. but if i try to pass the array into my custom function. Shabam. the internet breaks. Yeah not as dramatic but it doesn’t give the expected result. as best as i can figure. is that since in C the name of the array is the address to the first element of the array, that and only that element is used in the calculation of the sizeof() function. But why though is my question.

  int TempArray[] = {1, 2,3,4,5,6}; //pass this array into the function below

void MakeBoundArray(int low, int inc, int array[]) {

  int x = sizeof(array) / sizeof(int); returns 1
  for (int i = 0; i < x; i = i + 1) {
    array[i] = (low +( i * inc));

In the code you posted there is no point at which MakeBoundArray is called. I suspect that is your problem; you never call MakeBoundArray.

sizeof a pointer. Usually a constant. A small one too

if you want to find the size of an array you do sizeof(yourArray)/ sizeof(ArrayType)

That's very true. Unfortunately, you're not finding the size of an array, because the function cannot see an array, only a pointer

template<class TYPE, size_t LENGTH>
inline size_t num_entries(TYPE (&arr)[LENGTH])
    return LENGTH;

template<typename TYPE, size_t LENGTH>
void initBoundedArray(int low, int inc, TYPE (&array)[LENGTH])
    for ( size_t count = LENGTH, i = 0; count--; i++ )
        array[i] = low + (i * inc);

void loop()
{   }

void setup()

    int a_numerals[] = { 1, 2, 3, 4, 5, 6 };

    initBoundedArray(100, 5, a_numerals);

    const size_t NUM_ENTRIES = num_entries(a_numerals);

    for ( size_t i = 0; i < NUM_ENTRIES; i++ )

Or you could just pass the length into the function