sizes of arrays within functions
In C, i used a define when i first was learning which was something like:
Code:
#define LENGTH(array) (sizeof(array)/sizeof(array[0]))
or something along those lines in order to be able to figure out the length of integer arrays (char arrays are easier).
I was just curious about passing integer arrays to functions either to read them or modify them, and if I can find out their length.
For example,
Code:
int main(){
int array[5];
printf( "Length: %d", LENGTH(array) );
foo(array);
}
void foo( int array[] )
{
printf( "Length: %d, LENGTH(array) ); //does this work?
}
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.