y
is an array of integers with 10 members (size=40 Bytes) but when I pass it to my_function()
as x
, x
has 10 members but if I try to get it's size (sizeof(x)
) I will get 8 Bytes as result.
Could you please explain why this happens ?
void my_function(int x[]) {
printf("%d\n", sizeof(x)/sizeof(x[0]));
}
int main() {
int y[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
printf("%d\n", sizeof(y)/sizeof(y[0])); // Output : 10
my_function(y); // Output : 2
return 0;
}