Skip to main content
1 of 4
unwind
  • 401.8k
  • 64
  • 492
  • 620

Sigh.

Arrays decay to pointers in function calls. It's not possible to compute the size of an array which is only represented as a pointer in any way, including using sizeof.

You must add an explicit argument:

void show(int *data, size_t count); 

In the call, you can use sizeof to compute the number of elements, for actual arrays:

int arr[] = { 1,2,3,4,5 }; show(data, sizeof arr / sizeof *arr); 

Note that sizeof gives you the size in units of char, which is why the division by what is essentially sizeof (int) is needed, or you'd get a way too high value.

unwind
  • 401.8k
  • 64
  • 492
  • 620