In C, i used a define when i first was learning which was something like:
or something along those lines in order to be able to figure out the length of integer arrays (char arrays are easier).Code:#define LENGTH(array) (sizeof(array)/sizeof(array[0]))
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,
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.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? }



LinkBack URL
About LinkBacks


