does not seem to matter how I pass it, I only get two elements in a function. BUT, I think the real question here is how to pass an array, then do sizeof on it, to elevate the ( an ) unknown size of the array?
Code:
#include <stdio.h>
void fun_array(int a[])
//void fun_array(int* a)
{
int size = 0, j;
size = sizeof(&a)/sizeof(int);
//size = sizeof(a)/sizeof(a[0]);
printf("size %d\n", size);
for (j = 0; j < size; j++)
printf("%d\n", a[j]);
}
void fun_array2(int d[])
{
for (int s = 0; s < 6; s++)
printf("d = %d\n", d[s]);
}
int main()
{
int a[10] = {1, 2, 3, 4, 5, 6};
fun_array(a);
for (int s = 0; s < sizeof(a)/sizeof(a[0]); s++)
printf("\n\nin Main: %d\n", a[s]);
fun_array2(a);
return 0;
}
Code:
userx@slackwhere:~/bin
$ ./arrayPassFunction
size 2
1
2
in Main: 1
in Main: 2
in Main: 3
in Main: 4
in Main: 5
in Main: 6
in Main: 0
in Main: 0
in Main: 0
in Main: 0
d = 1
d = 2
d = 3
d = 4
d = 5
d = 6