xxxxxxxxxx
void return_array(char *arr, int size) {
for(int i = 0; i < size; i++)
arr[i] = i;
}
int main() {
int size = 5;
char arr[size];
return_array(arr, size);
}
xxxxxxxxxx
// fill a preallocated buffer provided by
// the caller (caller allocates buf and passes to the function)
void foo(char *buf, int count) {
for(int i = 0; i < count; ++i)
buf[i] = i;
}
int main() {
char arr[10] = {0};
foo(arr, 10);
// No need to deallocate because we allocated
// arr with automatic storage duration.
// If we had dynamically allocated it
// (i.e. malloc or some variant) then we
// would need to call free(arr)
}