-1

What is the proper way to return an array from a function in C? considering the caller doesn't know the size of the array, but without its size he cannot iterate over the array.

edit: just to clarify, the caller doesn't and shouldn't know the size of the returned array when calling the function.

CyberGK
  • 47
  • 6

1 Answers1

2

Return a struct where first element is the size and the second is the pointer to array.

struct size_and_array 
{
 int size;
 int* array; 
};
srknzl
  • 776
  • 5
  • 13