I was also curious as to the proper way to pass and integer array to a function. Can i pass it as int array[] if I want to read and modify it? Or should I be using int *array? If I use int *array will the LENGTH define even work? Thanks.

Once an array is passed to a function, it degrades to a pointer to the array, which means sizeof(array) will only give you the size of the pointer. The way around this is to pass the size of the array to the function.

that's what i thought, but was hoping there was another answer. That's too bad, i was even thinking of writing a function to do it for me but i would never know when to stop counting positions in an array and probably go past a valid index.....

I was also curious as to the proper way to pass and integer array to a function. Can i pass it as int array[] if I want to read and modify it? Or should I be using int *array? If I use int *array will the LENGTH define even work? Thanks.

In a function declaration, there is no difference between int *array and int array[]; that is to say, the following are identical:

Code:

void f(int a[]);
void f(int *a);

Both of these actually mean (in this particular instance) “pointer to int”. As such, if you modify what a points to, it will be changed in the calling function. The LENGTH macro will work in the sense that it will give you a value, but the value will still be useless.