You can't pass an array as an argument.
You can pass a pointer to its first element:
#include <stdio.h>
void test( size_t n, int *p ) { // `p` is a pointer an `int`.
printf( "%zu\n", sizeof(p) ); // `sizeof( int* )`, 8 for me.
printf( "%zu\n", sizeof(*p) ); // `sizeof( int )`, 4 for me.
printf( "%d\n", p[0] ); // 1
printf( "%d\n", p[1] ); // 2
}
int main( void ) {
int arr[] = {1,2,3,4,5,6,7,8,9,10,11};
test( sizeof(arr)/sizeof(*arr), arr );
}
Same thing in disguise:
#include <stdio.h>
void test( size_t n, int p[n] ) { // `p` is a pointer an `int`.
printf( "%zu\n", sizeof(p) ); // `sizeof( int* )`, 8 for me.
printf( "%zu\n", sizeof(*p) ); // `sizeof( int )`, 4 for me.
printf( "%d\n", p[0] ); // 1
printf( "%d\n", p[1] ); // 2
}
int main( void ) {
int arr[] = {1,2,3,4,5,6,7,8,9,10,11};
test( sizeof(arr)/sizeof(*arr), arr );
}
Finally, you could pass a pointer to the array:
#include <stdio.h>
void test( size_t n, int (*p)[n] ) { // `p` is a pointer to an `int[11]`
printf( "%zu\n", sizeof(p) ); // `sizeof( int* )`, 8 for me.
printf( "%zu\n", sizeof(*p) ); // `sizeof( int[11] )`, 44 for me.
printf( "%d\n", (*p)[0] ); // 1
printf( "%d\n", (*p)[1] ); // 2
}
int main( void ) {
int arr[] = {1,2,3,4,5,6,7,8,9,10,11};
test( sizeof(arr)/sizeof(*arr), &arr );
}
In any case, you will need the pass the size of the array if you need it, because it's not stored anywhere in the array itself.